Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Using int's in matlab

  • 23-03-2005 06:56PM
    #1
    Users Awaiting Email Confirmation Posts: 729 ✭✭✭


    Ok I'm having trouble using matlab.

    Let's say I want to find the n'th term of an array. i.e somearray(n)

    The only problem is that n has to be an int. In other words it cannot be 1.2335. I'm using a mathematical equation to find n, which will inevitably lead to decimal places in this case. How do I truncate 'n' in this instance so that it takes the value of the nearest whole number?????? In other words how do I make n a simple whole number, as opposed to a "double array" as it seems to be by default..


Comments

  • Registered Users, Registered Users 2 Posts: 1,171 ✭✭✭causal


    RTFM

    Let he who has not tried, cast the first stone...

    <splash>

    causal


  • Users Awaiting Email Confirmation Posts: 729 ✭✭✭popinfresh


    ????.

    How do you change the class of the value. Using matlab now, I know how to do it in C.


  • Registered Users, Registered Users 2 Posts: 1,171 ✭✭✭causal


    Did you not read the link in my last post?

    It says
    MATLAB Function Reference
    cast
    
    Cast variable to different data type
    
    Syntax
    
        *
    
    B = cast(A, newclass)
    
    Description
    
    B = cast(A, newclass) casts A to class newclass. A must be convertible to class newclass. newclass must be the name of one of the built in data types.
    
    Examples
    
        *
    
    a = int8(5);
    b = cast(a,'uint8');
    class(b)
    
    ans =
    
    uint8
    

    causal


  • Users Awaiting Email Confirmation Posts: 729 ✭✭✭popinfresh


    heh, didn't notice the link. Nice one casual


  • Registered Users, Registered Users 2 Posts: 1,171 ✭✭✭causal


    No problemo :)
    Everyone is entitled to be a little tired at that hour of the morning.

    causal


  • Advertisement
Advertisement