Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Finding numbers over a value in a matrix/array

Asked by Brian

Brian (view profile)

on 14 Jun 2013

Hi, I have a 365x10 matrix/array? not sure what it would be called need to find the amount of numbers in a certain range/below a certain value eg 0.

Thanks for any help.

0 Comments

Brian

Brian (view profile)

Products

No products are associated with this question.

3 Answers

Answer by Image Analyst

Image Analyst (view profile)

on 14 Jun 2013
Edited by Image Analyst

Image Analyst (view profile)

on 14 Jun 2013
Accepted answer

Try this:

T = rand(365,10);  % Some random data
% Define the range as [0, 0.2].
rangesLowValue = 0;
rangesHighValue = 0.2;
% Count the number of values in the range:
countLessThanPoint3 = sum(T(:) >= rangesLowValue & T(:)<rangesHighValue)

3 Comments

Brian

Brian (view profile)

on 14 Jun 2013

Thanks, I'm really not getting this though.

I have a pre-defined matrix of real data, this is what I wrote:

load('temp.mat')
disp(T);
ranges High Value = 0
count Less than point3=sum(T(:) <= ranges High Value

but I'm doing something wrong clearly ...

Image Analyst

Image Analyst (view profile)

on 14 Jun 2013

Yes. You can't write variable names with spaces in them. Plus I don't know why you didn't just do it like I said. Explain what this means " in a certain range/below a certain value eg 0." Do you mean that the limits of the entire range (both the low and high values) are less than 0? Like the low value = -999 and the high value is -1?

Brian

Brian (view profile)

on 15 Jun 2013

\Thanks a lot..I'm really new to matlab as you may have noticed.

Image Analyst

Image Analyst (view profile)

Answer by Andrei Bobrov

Andrei Bobrov (view profile)

on 14 Jun 2013
A = rand(20,10); 
A(A < .3) = -A(A < .3); % your array
out = nnz(A < 0);

1 Comment

Brian

Brian (view profile)

on 14 Jun 2013

Hi thanks,

when I use the following I get the answer for the first part, the numbers less than 0, but I'm doing something wrong in the second, it says '??? Index exceeds matrix dimensions.' what do I do?

Andrei Bobrov

Andrei Bobrov (view profile)

Answer by Azzi Abdelmalek

Azzi Abdelmalek (view profile)

on 14 Jun 2013
range=2
idx=find(abs(yourarray)<range)

0 Comments

Azzi Abdelmalek

Azzi Abdelmalek (view profile)

Contact us