Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Using int's in matlab

Options
  • 23-03-2005 6: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 Posts: 1,184 ✭✭✭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 Posts: 1,184 ✭✭✭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 Posts: 1,184 ✭✭✭causal


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

    causal


  • Advertisement
Advertisement