How to show Column and Row numbers in Matrix
    6 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Sahil Bajaj
 am 29 Nov. 2015
  
    
    
    
    
    Bearbeitet: Mohammad Abouali
      
 am 29 Nov. 2015
            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 Kommentare
Akzeptierte Antwort
  Mohammad Abouali
      
 am 29 Nov. 2015
        
      Bearbeitet: Mohammad Abouali
      
 am 29 Nov. 2015
  
      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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


