Got Questions? Get Answers.
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

Thread Subject:
elements in array

Subject: elements in array

From: Puneet

Date: 12 Aug, 2013 10:23:07

Message: 1 of 4

is there any way to extract elements from an array for a given range of values for example between o and 1 ?

Subject: elements in array

From: Kevin Hellemans

Date: 12 Aug, 2013 13:46:10

Message: 2 of 4

Yes:

% Create array with random number between 0 and 1
x = rand(10,5)*2;

% Extract elements for which 0 < x < 1
y = x(x<1 & x > 0);

Subject: elements in array

From: someone

Date: 12 Aug, 2013 13:49:10

Message: 3 of 4

"Puneet" wrote in message <kuad2b$fqa$1@newscl01ah.mathworks.com>...
> is there any way to extract elements from an array for a given range of values for example between o and 1 ?

% Use logical indexing:

<<http://www.mathworks.com/help/matlab/math/matrix-indexing.html#bq7egb6-1>>

% For example, something like:

A = rand(5);
B = A > 0.5;

% should get you started.

Subject: elements in array

From: Puneet

Date: 13 Aug, 2013 06:51:07

Message: 4 of 4

"someone" wrote in message <kuap4m$fn2$1@newscl01ah.mathworks.com>...
> "Puneet" wrote in message <kuad2b$fqa$1@newscl01ah.mathworks.com>...
> > is there any way to extract elements from an array for a given range of values for example between o and 1 ?
>
> % Use logical indexing:
>
> <<http://www.mathworks.com/help/matlab/math/matrix-indexing.html#bq7egb6-1>>
>
> % For example, something like:
>
> A = rand(5);
> B = A > 0.5;
>
> % should get you started.


this is what i was looking for....it worked

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us