Filter löschen
Filter löschen

obtain a sequence from a matrix

1 Ansicht (letzte 30 Tage)
Elysi Cochin
Elysi Cochin am 12 Mai 2016
Kommentiert: Elysi Cochin am 13 Mai 2016
i have a matrix as shown below
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 Kommentar
Sivakumaran Chandrasekaran
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Guillaume
Guillaume am 12 Mai 2016
Bearbeitet: Guillaume am 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

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by