location of element in matrix

1 vue (au cours des 30 derniers jours)
jano satti
jano satti le 25 Avr 2017
Modifié(e) : Andrei Bobrov le 25 Avr 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.
  1 commentaire
Stephen23
Stephen23 le 25 Avr 2017
Modifié(e) : Stephen23 le 25 Avr 2017

Connectez-vous pour commenter.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 25 Avr 2017
Modifié(e) : Andrei Bobrov le 25 Avr 2017
[l0,ii] = ismembertol(mat(:),x);
[i0,j0] = ind2sub(size(mat),find(l0));
[~,i1] = sort(ii(l0));
out = [i0,j0];
out = out(i1,:);

Plus de réponses (2)

Stephen23
Stephen23 le 25 Avr 2017

Azzi Abdelmalek
Azzi Abdelmalek le 25 Avr 2017
Use ismember function

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by