i have a matrix like [1 0 0 1 0 1 0 ; 0 1 0 1 0 0 ; 1 0 0 1 1 1]. there are 3 rows and 7 column i wanna to see in the format like

1 view (last 30 days)
i have a matrix like [1 0 0 1 0 1 0 ; 0 1 0 1 0 0 ; 1 0 0 1 1 1]. there are 3 rows and 7 column i wanna to see in the format like [ 1 1 1; 1 2 0; 1 3 0; 1 4 1; 1 5 0 ; 1 6 1; 1 7 0; 2 1 ; 2 2...;]

Accepted Answer

Stephen23
Stephen23 on 4 Jun 2018
>> M = [1 0 0 1 0 1 ; 0 1 0 1 0 0 ; 1 0 0 1 1 1]
M =
1 0 0 1 0 1
0 1 0 1 0 0
1 0 0 1 1 1
>> S = size(M);
>> [R,C] = ndgrid(1:S(1),1:S(2));
>> sortrows([R(:),C(:),M(:)])
ans =
1 1 1
1 2 0
1 3 0
1 4 1
1 5 0
1 6 1
2 1 0
2 2 1
2 3 0
2 4 1
2 5 0
2 6 0
3 1 1
3 2 0
3 3 0
3 4 1
3 5 1
3 6 1

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!