필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Zeab
Zeab 2020년 4월 16일
편집: Zeab 2020년 4월 16일
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