-90 to +90 degree in matlab

Status
Not open for further replies.
Hi,

I know this, theta = 180*randi generates 0 to 180 randomly, but it is now -90 to 90 where negative values comes in, thats why I am asking

thanks
 
If this is true:
I know this, theta = 180*randi generates 0 to 180 randomly, but it is now -90 to 90 where negative values comes in, thats why I am asking
Then surely
Code:
theta = 180*randi - 90
will get you a number in {-90, ..., +90}.
 
What dougy83 said is true.

And if you just bothered to read the matlab help I linked, you would easily find that:

r = randi([-90 90], 100, 1);
Returns an 100x1 array of random values between -90...90.

So if you need only one random number at a time, I think one of these (or all of them) should return one random number between -90...90 :
r = randi([-90 90]); or
r = randi([-90 90], 1); or
r = randi([-90 90], 1, 1);

https://www.mathworks.se/help/matlab/ref/randi.html
 
Last edited:
r = randi([-90 90])

That seems to work ok. I tried it out here:
https://octave-online.net/

Nice online tool btw. Try it out with the command line inputs:

octave:1> figure
octave:2> hold
octave:3> r = randi([-90 90], 1000, 1);
octave:4> plot(r);
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…