False size for row vector
2 ビュー (過去 30 日間)
古いコメントを表示
I would like to create the row vector T1=[1 2 4 8 14 15 9 16 17 5 10 18 19 1 21 20 3 6 12 13 7] with one column 1-21, which is seperated in column 1-19 and 20-21 but I always get the column 1-17 and 18-21.
What can I do to get the right sizing?
9 件のコメント
Steven Lord
2024 年 1 月 10 日
With the standard display? No, not really. You have some control of the display format but that doesn't give you fine-grained control ("I want exactly N elements per line", for example.)
disp(0.5+(1:100))
format long % long fixed point format
format compact % suppress excess blank lines
disp(0.5+(1:100))
With a command like fprintf? Sure, as long as you can construct the format string to your specifications. Note that the format string in this example does not contain a newline, so fprintf prints it all as one long line of text.
fprintf('%g\t', 0.5+(1:100))
If I wanted to display this in lines of say 60 characters, I could do that using sprintf to create the text then textwrap to wrap it.
s = sprintf('%g ', 0.5+(1:100));
s2 = string(textwrap({s}, 60))
strlength(s2)
回答 (1 件)
Ayush Anand
2024 年 1 月 10 日
Hi Sveva,
The MATLAB command window has a default width that determines how many columns of a vector it will display on one line before wrapping around to the next line. If you're seeing the vector T1 split into two lines with the first line showing elements 1-17 and the second line showing elements 18-21, this is due to the command window's width settings.
MATLAB automatically formats the output to fit within the command window's width. You cannot directly control where the line break occurs in the command window's display of a long vector. However, you can manually drag and resize the command window width to change where the break occurs. A wide enough command window will display all the elements in one row, you can do trial and error to resize the window to get columns 1-19 and 20-21.
I hope this helps!
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!