location of element in matrix

1 visualizzazione (ultimi 30 giorni)
jano satti
jano satti il 25 Apr 2017
Modificato: Andrei Bobrov il 25 Apr 2017
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.

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 25 Apr 2017
Modificato: Andrei Bobrov il 25 Apr 2017
[l0,ii] = ismembertol(mat(:),x);
[i0,j0] = ind2sub(size(mat),find(l0));
[~,i1] = sort(ii(l0));
out = [i0,j0];
out = out(i1,:);

Più risposte (2)

Stephen23
Stephen23 il 25 Apr 2017

Azzi Abdelmalek
Azzi Abdelmalek il 25 Apr 2017
Use ismember function

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by