Compare 2d array with multiple numbers at same time and get the position

Hi, I am trying to find a way to compare a 2d array with different numbers and get the position of the elements at same time without a loop.
I know I could use 'find' function to get the position contain different value use a for loop but I can't use it simultaneously since the length of positions is different.
x=10;
array=randi(10,10)
for i=1:x
[order]=find(array==i);
% some calculation with the order and array here
end
So I could manage this with a for loop but its quite slow, is there a better way to achieve this?
Thanks

回答 (1 件)

Image Analyst
Image Analyst 2018 年 8 月 29 日
Try this:
[rows, columns] = find(array == x);

2 件のコメント

Li zifan
Li zifan 2018 年 8 月 29 日
What I want to do is is like
find(array == (1:k));
Thanks for your advise though.
Image Analyst
Image Analyst 2018 年 8 月 29 日
Perhaps you want ismember().

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2018 年 8 月 29 日

コメント済み:

2018 年 8 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by