location of element in matrix

조회 수: 1 (최근 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.

채택된 답변

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일

Azzi Abdelmalek
Azzi Abdelmalek 2017년 4월 25일
Use ismember function

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by