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

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

Risposte (1)

>> 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 Commenti

Zeab
Zeab il 16 Apr 2020
Modificato: Zeab il 16 Apr 2020
Thanks dear,working perfect in the comand window actually my intention is to make it neat in the script, Editor page.
"And then copy and paste that into your code."
Zeab
Zeab il 16 Apr 2020
Modificato: Zeab il 16 Apr 2020
Thanks, sorry if that's not too much to ask and if you look at the attachement in my first query, I have input the elemnts of the matrix and then it looks poorly spaced.I was wondering how to make neat and proper spacing between matrices elements in the script window. The above code will display the proper spacing in the comand window after we make a run of the script file.
Thank you again
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 il 16 Apr 2020
Modificato: Zeab il 16 Apr 2020
"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!

Accedi per commentare.

Categorie

Prodotti

Tag

Richiesto:

il 16 Apr 2020

Modificato:

il 16 Apr 2020

Community Treasure Hunt

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

Start Hunting!

Translated by