False size for row vector

2 ビュー (過去 30 日間)
Sveva
Sveva 2024 年 1 月 10 日
コメント済み: Torsten 2024 年 1 月 10 日
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
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))
Columns 1 through 19 1.5000 2.5000 3.5000 4.5000 5.5000 6.5000 7.5000 8.5000 9.5000 10.5000 11.5000 12.5000 13.5000 14.5000 15.5000 16.5000 17.5000 18.5000 19.5000 Columns 20 through 38 20.5000 21.5000 22.5000 23.5000 24.5000 25.5000 26.5000 27.5000 28.5000 29.5000 30.5000 31.5000 32.5000 33.5000 34.5000 35.5000 36.5000 37.5000 38.5000 Columns 39 through 57 39.5000 40.5000 41.5000 42.5000 43.5000 44.5000 45.5000 46.5000 47.5000 48.5000 49.5000 50.5000 51.5000 52.5000 53.5000 54.5000 55.5000 56.5000 57.5000 Columns 58 through 76 58.5000 59.5000 60.5000 61.5000 62.5000 63.5000 64.5000 65.5000 66.5000 67.5000 68.5000 69.5000 70.5000 71.5000 72.5000 73.5000 74.5000 75.5000 76.5000 Columns 77 through 95 77.5000 78.5000 79.5000 80.5000 81.5000 82.5000 83.5000 84.5000 85.5000 86.5000 87.5000 88.5000 89.5000 90.5000 91.5000 92.5000 93.5000 94.5000 95.5000 Columns 96 through 100 96.5000 97.5000 98.5000 99.5000 100.5000
format long % long fixed point format
format compact % suppress excess blank lines
disp(0.5+(1:100))
1.0e+02 * Columns 1 through 9 0.015000000000000 0.025000000000000 0.035000000000000 0.045000000000000 0.055000000000000 0.065000000000000 0.075000000000000 0.085000000000000 0.095000000000000 Columns 10 through 18 0.105000000000000 0.115000000000000 0.125000000000000 0.135000000000000 0.145000000000000 0.155000000000000 0.165000000000000 0.175000000000000 0.185000000000000 Columns 19 through 27 0.195000000000000 0.205000000000000 0.215000000000000 0.225000000000000 0.235000000000000 0.245000000000000 0.255000000000000 0.265000000000000 0.275000000000000 Columns 28 through 36 0.285000000000000 0.295000000000000 0.305000000000000 0.315000000000000 0.325000000000000 0.335000000000000 0.345000000000000 0.355000000000000 0.365000000000000 Columns 37 through 45 0.375000000000000 0.385000000000000 0.395000000000000 0.405000000000000 0.415000000000000 0.425000000000000 0.435000000000000 0.445000000000000 0.455000000000000 Columns 46 through 54 0.465000000000000 0.475000000000000 0.485000000000000 0.495000000000000 0.505000000000000 0.515000000000000 0.525000000000000 0.535000000000000 0.545000000000000 Columns 55 through 63 0.555000000000000 0.565000000000000 0.575000000000000 0.585000000000000 0.595000000000000 0.605000000000000 0.615000000000000 0.625000000000000 0.635000000000000 Columns 64 through 72 0.645000000000000 0.655000000000000 0.665000000000000 0.675000000000000 0.685000000000000 0.695000000000000 0.705000000000000 0.715000000000000 0.725000000000000 Columns 73 through 81 0.735000000000000 0.745000000000000 0.755000000000000 0.765000000000000 0.775000000000000 0.785000000000000 0.795000000000000 0.805000000000000 0.815000000000000 Columns 82 through 90 0.825000000000000 0.835000000000000 0.845000000000000 0.855000000000000 0.865000000000000 0.875000000000000 0.885000000000000 0.895000000000000 0.905000000000000 Columns 91 through 99 0.915000000000000 0.925000000000000 0.935000000000000 0.945000000000000 0.955000000000000 0.965000000000000 0.975000000000000 0.985000000000000 0.995000000000000 Column 100 1.005000000000000
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))
1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5 14.5 15.5 16.5 17.5 18.5 19.5 20.5 21.5 22.5 23.5 24.5 25.5 26.5 27.5 28.5 29.5 30.5 31.5 32.5 33.5 34.5 35.5 36.5 37.5 38.5 39.5 40.5 41.5 42.5 43.5 44.5 45.5 46.5 47.5 48.5 49.5 50.5 51.5 52.5 53.5 54.5 55.5 56.5 57.5 58.5 59.5 60.5 61.5 62.5 63.5 64.5 65.5 66.5 67.5 68.5 69.5 70.5 71.5 72.5 73.5 74.5 75.5 76.5 77.5 78.5 79.5 80.5 81.5 82.5 83.5 84.5 85.5 86.5 87.5 88.5 89.5 90.5 91.5 92.5 93.5 94.5 95.5 96.5 97.5 98.5 99.5 100.5
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))
s2 = 10×1 string array
"1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 " "12.5 13.5 14.5 15.5 16.5 17.5 18.5 19.5 20.5 21.5 " "22.5 23.5 24.5 25.5 26.5 27.5 28.5 29.5 30.5 31.5 " "32.5 33.5 34.5 35.5 36.5 37.5 38.5 39.5 40.5 41.5 " "42.5 43.5 44.5 45.5 46.5 47.5 48.5 49.5 50.5 51.5 " "52.5 53.5 54.5 55.5 56.5 57.5 58.5 59.5 60.5 61.5 " "62.5 63.5 64.5 65.5 66.5 67.5 68.5 69.5 70.5 71.5 " "72.5 73.5 74.5 75.5 76.5 77.5 78.5 79.5 80.5 81.5 " "82.5 83.5 84.5 85.5 86.5 87.5 88.5 89.5 90.5 91.5 " "92.5 93.5 94.5 95.5 96.5 97.5 98.5 99.5 100.5"
strlength(s2)
ans = 10×1
57 60 60 60 60 60 60 60 60 53
Torsten
Torsten 2024 年 1 月 10 日
That's helpful. Many thanks @Steven Lord

サインインしてコメントする。

回答 (1 件)

Ayush Anand
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 件のコメント
Sveva
Sveva 2024 年 1 月 10 日
Hi Ayush, thank you for your help! What do you mean exactly with "manually drag and resize"; how can I acchieve this?
Voss
Voss 2024 年 1 月 10 日

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by