False size for row vector
3 次查看(过去 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!
另请参阅
类别
在 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!