How to show Column and Row numbers in Matrix
2 次查看(过去 30 天)
显示 更早的评论
I have a matrix
1 2 3
4 5 6
7 8 9
I want
- 1 2 3
1 1 2 3
2 4 5 6
3 7 8 9
2 个评论
采纳的回答
Mohammad Abouali
2015-11-29
编辑:Mohammad Abouali
2015-11-29
A=[1 2 3
40 5 6
7 800 9];
format = sprintf('%%%d',max(floor(log10(A(:)))+1));
fprintf([format 'c '],'-');
fprintf([format 'd '],1:size(A,2));
fprintf('\n');
for rowN=1:size(A,2)
fprintf([format 'd '],[rowN, A(rowN,:)])
fprintf('\n');
end
- 1 2 3
1 1 2 3
2 40 5 6
3 7 800 9
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!