N by N dimensional matrix row and column spacing in mat lab script

1 次查看(过去 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

回答(1 个)

Walter Roberson
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
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
]
Zeab
Zeab 2020-4-16
编辑:Zeab 2020-4-16
"You can copy the output of the num2str() with your mouse and paste it over your existing matrix"
I just got your point,fixed!
Thanks a lot!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by