obtain a sequence from a matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Elysi Cochin
le 12 Mai 2016
Commenté : Elysi Cochin
le 13 Mai 2016
i have a matrix as shown below
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/164128/image.png)
from the above matrix "M" of size 11 x 11, i need to get "output" of size 1 x 11... i need to get a sequence written in red color below the image...
start from i = 1; M(i,1); save output = M(i,1); go to the i = 2; M(i,1); eg: 4 go to 1st row of 4th col; M(1,4) - save that to output = [1 4]; go to M(2,4) - go to that column - i.e. M(1,2) - save that to output = [1 4 2] repeat till all numbers from 1 to 11 are obtained without repetion..
if repeated go to M(j,col) where j is the non-repeated row value of that particular column....
please can someone help me how to goto the column i need ....
1 commentaire
Sivakumaran Chandrasekaran
le 12 Mai 2016
initially you practise with input having 1 column, after understanding proceed for two columns, after understanding proceed for three columns.. then proceed for this image which you shared. you will get it.
Réponse acceptée
Guillaume
le 12 Mai 2016
Modifié(e) : Guillaume
le 12 Mai 2016
Please post matlab code in addition to a picture so we don't have to type your matrix ourselves.
M = [1 2 3 4 5 6 7 8 9 10 11;
4 5 6 5 2 5 4 5 6 1 3;
10 4 11 2 4 2 10 4 11 7 9;
2 6 2 8 6 8 8 6 8 4 6]; %demo data shortened as I'm not going to type it all
v = M(1, 1); %starting point
currentcolumn = 1;
while currentcolumn
currentcolumn = M(find(~ismember(M(:, currentcolumn), v), 1), currentcolumn); %find the 1st row of M(:, currentcolumn) that is not a member of V. Use the value at that row as the new currentcolumn
v = [v, currentcolumn];
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Data Workflows 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!