UKC

MatLab gaaah

New Topic
This topic has been archived, and won't accept reply postings.
 Blue Straggler 02 Nov 2009
Trying to isolate a range in an array. It is going wrong. This should be simple, so I decided to test a simple example.
a = [1 4 6 8 99 255 4000]

7 numbers. Let's say we want to see which ones lie within a range.

I'd have thought
range=find(4<a<=120)
would find the values 6, 8 and 99 for me, and output their positions in the array i.e.
range = 3 4 5
And I could then call those values up by typing
a(range)

What I get is
range =

1 2 3 4 5 6 7

Since when were 255 and 4000 less than 120??

The same thing is happening in the real application.
What on Earth am I doing wrong?!
 oliwarlow 02 Nov 2009
In reply to Blue Straggler:

Its a stupid thing in Matlab, for that function you need an & symbol

i.e.


range=find(4<a & a<=120)


gives 3 4 5 as expected

hope this helps

O
 Liam M 02 Nov 2009
In reply to Blue Straggler: I have very limited knowledge of Matlab, so could be very wrong, but are you using the range command correctly?

http://www.geo.cornell.edu/grads/duncan/gcm/anal/matlab/range.html suggests that range command is used to find the range of values in an array, rather than to define the minimum and maximum values you want to extract.

I'm not sure how you'd do what you want though - I'll have a scout around and see what I can suss.
In reply to oliwarlow:

Aha, yes that seems to be working, many many thanks. Couldn't find it easily in Help! (er MatLab help, not the Beatles' film)
In reply to Liam M:

Cheers Liam, "O" seems to have solved it. For clarity, I wasn't using range as a command, but as a variable name there.
 oliwarlow 02 Nov 2009
In reply to Blue Straggler:

no bother - a good way of finding things is to try and phrase your quesiton in a few words then type them into google along with the word 'matlab'. there are loads of help forums out there and chances are someone else had asked the same question at some point. Or ofcourse post on here, as there are plenty of us looking at climbing forums rather than working......

New Topic
This topic has been archived, and won't accept reply postings.
Loading Notifications...