N by N dimensional matrix row and column spacing in mat lab script
    4 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Dears,
It seems that elementary question but It tooks me a while to creat a new multi dimensional matrix in matlab script which is neatly spaced.Can anyone help me in fixing it?
MultD_matrix=[...
1	0	0	0	 3	1	0	12.66	1.1	0.9
2	0	0.6	0	3	1	0	12.66	1.1	0.9
3	0	0	0	3	1	0	12.66	1.1	0.9
4	0	0.9	0	3	1	0	12.66	1.1	0.9
5	0	0	0	3	1	0	12.66	1.1	0.9
6	2.6	2.2	0	3	1	0	12.66	1.1	0.9
7	40.4	30	0	3	1	0	12.66	1.1	0.9
8	75	54	0	3	1	0	12.66	1.1	0.9
9	30	22	0	3	1	0	12.66	1.1	0.9
10	28	19	0	3	1	0	12.66	1.1	0.9
11	145	104	0	3	1	0	12.66	1.1	0.9
12	145	104	0	3	1	0	12.66	1.1	0.9
13	8	5.5	0	3	1	0	12.66	1.1	0.9
14	8	5.5	0	3	1	0	12.66	1.1	0.9
15	0	0	0	3	1	0	12.66	1.1	0.9];
FYI while I copy and paste my sscript code here,it automtacially creat neat spacing ,you can check the attched file
0 件のコメント
回答 (1 件)
  Walter Roberson
      
      
 2020 年 4 月 16 日
        >> disp(num2str(MultD_matrix, '%g '))
 1     0     0     0     3     1     0 12.66   1.1   0.9
 2     0   0.6     0     3     1     0 12.66   1.1   0.9
 3     0     0     0     3     1     0 12.66   1.1   0.9
 4     0   0.9     0     3     1     0 12.66   1.1   0.9
 5     0     0     0     3     1     0 12.66   1.1   0.9
 6   2.6   2.2     0     3     1     0 12.66   1.1   0.9
 7  40.4    30     0     3     1     0 12.66   1.1   0.9
 8    75    54     0     3     1     0 12.66   1.1   0.9
 9    30    22     0     3     1     0 12.66   1.1   0.9
10    28    19     0     3     1     0 12.66   1.1   0.9
11   145   104     0     3     1     0 12.66   1.1   0.9
12   145   104     0     3     1     0 12.66   1.1   0.9
13     8   5.5     0     3     1     0 12.66   1.1   0.9
14     8   5.5     0     3     1     0 12.66   1.1   0.9
15     0     0     0     3     1     0 12.66   1.1   0.9
And then copy and paste that into your code.
You can also use, for example, 
disp(num2str(MultD_matrix, '%7g'))
5 件のコメント
  Walter Roberson
      
      
 2020 年 4 月 16 日
				No. You can copy the output of the num2str() with your mouse and paste it over your existing matrix.
Otherwise what you are asking me to do is write some code that will read in your .m file, find the matrix, reformat it, and write out the matrix again. That can be done, but I am not going to spend 20+ minutes writing it and testing it just to save you a few keystrokes. My code would have to worry about possibilities such as there appearing to be an assignment to the matrix but which was really commented out with % comments, or which was really commented out with %{ block comments, or which was part of a character vector, or about strange possibilities such as you having coded
MultD...
_...
matrix...
=...
[...
numbers
]
参考
カテゴリ
				Help Center および File Exchange で Matrix Indexing についてさらに検索
			
	製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!