Rearranging and printing matrices

Hello! I'm stuck on a problem that I thought would be really simple. I have a matrix A =
8 1 6
3 5 7
4 9 2
and would like it to be reprinted as:
1 1 8
1 2 3
1 3 4
2 1 1
2 2 5
2 3 9
3 1 6
3 2 7
3 3 2
with a single space between each number. Regardless of what I've tried I can't get it to print the way I would like. Any ideas? Thanks in advance!

 Accepted Answer

[i1,j1,v] = find(A)
out = [j1,i1,v]
variant 2 if A have zeros
[i1 j1] = ind2sub(size(A),(1:numel(A))')
out = [j1 i1 A(:)]
variant 3 with use meshgrid
[n m] =size(A)
[i1 j1] = meshgrid(1:n,1:m)
out = [i1(:) j1(:) A(:)]

More Answers (0)

Categories

Find more on MATLAB 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!