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

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 11 日

1 投票

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.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by