obtain a sequence from a matrix
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Sivakumaran Chandrasekaran
2016-5-12
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.
采纳的回答
Guillaume
2016-5-12
编辑:Guillaume
2016-5-12
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!