Hi,
I'm trying to extract a two column vector from another two column vector using a logical statement.
For example, if column one contains x values and column two the corresponding y values, I want to create another matrix that contains only the x and y values when x is equal to a particular number. Here's the code I've used:
extracted_data=initial_data(initial_data==0,:);
This seems to work for some small test matrices. However, when I try to scale it up to extracting data from a vector with 64516 rows, I get the following error:
??? Index exceeds matrix dimensions.
Any ideas how I can avoid this? I've achieved the result I want using a loop and "if" statements, but this is SLOW!
Many thanks in advance,
T

 Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 11 Aug. 2011

1 Stimme

It is not the number of rows. Your code won't work for nx2 array. You need to do this:
initial_data=rand(10,2);
extracted_data=initial_data(initial_data(:,1)<0.5,:)
Also, pay attention to "==0" if your data is floating point.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by