How to show Column and Row numbers in Matrix

조회 수: 1 (최근 30일)
Sahil Bajaj
Sahil Bajaj 2015년 11월 29일
편집: Mohammad Abouali 2015년 11월 29일
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
Jan
Jan 2015년 11월 29일
편집: Jan 2015년 11월 29일
Did you see, that the question looks funny without a proper formatting? I've marked the matrices and hit the "{} Code" button to make the question readable.
What should happen, when large values appear?
Sahil Bajaj
Sahil Bajaj 2015년 11월 29일
If it is 4*4 matrix
- 1 2 3 4
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1

댓글을 달려면 로그인하십시오.

채택된 답변

Mohammad Abouali
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개)

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by