Skip to main content
GameDev.net gamedev.net
🔒 Locked

Matlab question

Started by theo2008 Mar 20, 2009 at 5:09 AM 6 replies 1.5k views
Original Post
theo2008
theo2008
Hi!! Does anyone knows how can i write this in matlab? y= 4e11 5e11 6e11 7e11 8e11 9e11 1e12 2e12 I tried this y=(4e11:1e11:2e12).' but is wrong. It gaves me these results: 4e11 5e11 6e11 7e11 8e11 9e11 1e12 1.1e12 1.2e12 . . 1.9e12 2e12 and not the results which i want!! Thank you!!!
Brother Bob
Brother Bob
Your problem is not trivially solved with the range operators, because they are for linear ranges and your desired range is nonlinear. The step size changes suddenly from 1e11 to 1e12 when reaching 9e11. But for 8 values, just write them manually.
Brother Bob
Brother Bob
Or if you actually want longer ranges, you can do this.
reshape((1:9).' * 10.^(0:3), [], 1)

Adjust the (0:3) range depending on what powers you want, and then trim the resulting vector to desired start and end values.
theo2008
theo2008
or if i make something like that
y=[4e11:1e11:9e11,1e12:1e12:2e12].'
My problem is that these values are not static.The values(6e11-2e12) which i gave you,is as example.These values can be 3e9-4e11,1e9-9e9,3e10-3e11 etc.So, I must find a way when i give the limits(for example 3e9,4e11) then i would like matlab can give me automatically
3e9
4e9
.
.
.
9e10
1e11
2e11
3e11
4e11
Is there a way to do that?
Brother Bob
Brother Bob
Generate the sequence I posted code for and trim the start and end of the vector to your desired values.
jjd
jjd
Well, you could use the following,

n = [3:10];
x = ( mod( n, 9 ) + 1 ) .* 10.^floor( n / 9 );

But it's such a small series that it seems better to write it by hand. Perhaps this is just a simplification of a larger problem?

(note: you can sometimes get formulas (as above) for sequences from the encyclopedia of sequences)
theo2008
theo2008
I thought something else with Bob's solution:
My thought is to create a matrix(27x1)
mat=reshape((1:9).' * 10.^(9:11), [], 1)

After,i'll give the limits for example 3e9-4e11...
Hmmm...Now the problem is that i don't know if Matlab has commands to search these limits in matrix and then to give me the values between the limits.
Brother Bob
Brother Bob
Use masking to trim the range.
mat = reshape((1:9).' * 10.^(9:11), [], 1);mat(mat >= 3e9 & mat <= 4e11)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.