Extracting xy coordinate points from a matrix, based on a limit for x.

1 回表示 (過去 30 日間)
Nikan Fakhari
Nikan Fakhari 2020 年 10 月 8 日
回答済み: Ameer Hamza 2020 年 10 月 8 日
Hi there,
I have a xy matrix as follows that contains x and y points. From xy matrix I would like to extract points that their x values are between 2 and 5.
for example I would like to extract these points, (3,7) and (4,8) and save them in a new variable.
can anyone help me with this?
I would rather not use for loop because Im trying to do the same operation with a large data set and Im trying to avoid the use of for loop.
Thank you very much.
x = [1,2,3,4,5]
y = [5,6,7,8,9]
xy=[x;y]
Thank you very much.

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 10 月 8 日
Read about logical indexing
x = [1,2,3,4,5];
y = [5,6,7,8,9];
xy = [x;y];
idx = (x > 2) & (x < 5);
xy_new = xy(:, idx);

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by