location of element in matrix

2 ビュー (過去 30 日間)
jano satti
jano satti 2017 年 4 月 25 日
編集済み: Andrei Bobrov 2017 年 4 月 25 日
I have a matrix mat and I want to find location of x in mat matrix.location should be in order of x.
mat =[
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
0.0099 1.0000 1.0000 0.0120 1.0000 0.0115
0.0093 1.0000 1.0000 0.0120 1.0000 0.0070
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
0.0098 1.0000 1.0000 0.0089 1.0000 0.0093
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000];
x =[
0.0089
0.0099
0.0070];
A =mat
C=x
numbersInA = unique(C)
numbersInC = unique(C)
for k = 1 : length(numbersInA)
[rowA colA] = find(A==numbersInC(k))
w(k,:)= [rowA , colA]
end
ans is [ 3 6]
[5 4]
[2 1]
but I need this solution::
[5 4]
[2 1]
[3 6]
Thanks in advance.
  1 件のコメント
Stephen23
Stephen23 2017 年 4 月 25 日
編集済み: Stephen23 2017 年 4 月 25 日

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 4 月 25 日
編集済み: Andrei Bobrov 2017 年 4 月 25 日
[l0,ii] = ismembertol(mat(:),x);
[i0,j0] = ind2sub(size(mat),find(l0));
[~,i1] = sort(ii(l0));
out = [i0,j0];
out = out(i1,:);

その他の回答 (2 件)

Stephen23
Stephen23 2017 年 4 月 25 日
  1 件のコメント
Andrei Bobrov
Andrei Bobrov 2017 年 4 月 25 日
+1

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


Azzi Abdelmalek
Azzi Abdelmalek 2017 年 4 月 25 日
Use ismember function

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by