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:
find question

Subject: find question

From: Jonathan

Date: 1 Jun, 2011 15:59:04

Message: 1 of 3

G'day,

What is the trick when using find in order to be able to extract a portion of data from a matrix. For example, I have a matrix (n,10). I can use find to identify specific data of interest e.g.

[wI]=find(combined_data(:,2)==1 | combined_data(:,2)==2 | combined_data(:,2)==3);
ws = combined_data(:,7); wd = combined_data(:,8); dur = combined_data(:,9);
ws=ws(wI); wd=wd(wI); dur=dur(wI);
WD=[ws wd dur];

However, in this example I am having to select specific columns of data (2nd line), apply the index to each of those columns (3rd line) and then rebuild the new matrix. Is there a way to use the index to extract all 10 columns of data without breaking the matrix up into specific coulumns?

Thanks
Jon

Subject: find question

From: Matt J

Date: 1 Jun, 2011 16:35:20

Message: 2 of 3

"Jonathan" <jkakiwi@yahoo.co.uk> wrote in message <is5nk8$9jt$1@newscl01ah.mathworks.com>...
> G'day,
>
> What is the trick when using find in order to be able to extract a portion of data from a matrix.
==================

The trick is, first of all, not to use FIND at all (it's unnecessary here), and secondly, to apply the index to the row coordinates only. For example, you could have just done

 wI=(combined_data(:,2)==1 | combined_data(:,2)==2 | combined_data(:,2)==3);
 WD=combined_data(wI,7:9);

or if you wanted all 10 columns

WD=combined_data(wI,:);

Subject: find question

From: Jonathan

Date: 1 Jun, 2011 16:55:08

Message: 3 of 3

"Matt J" wrote in message <is5po8$fvq$1@newscl01ah.mathworks.com>...
> "Jonathan" <jkakiwi@yahoo.co.uk> wrote in message <is5nk8$9jt$1@newscl01ah.mathworks.com>...
> > G'day,
> >
> > What is the trick when using find in order to be able to extract a portion of data from a matrix.
> ==================
>
> The trick is, first of all, not to use FIND at all (it's unnecessary here), and secondly, to apply the index to the row coordinates only. For example, you could have just done
>
> wI=(combined_data(:,2)==1 | combined_data(:,2)==2 | combined_data(:,2)==3);
> WD=combined_data(wI,7:9);
>
> or if you wanted all 10 columns
>
> WD=combined_data(wI,:);

Thanks Matt, this helped.

Tags for 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