필터 지우기
필터 지우기

matlab display string in multiple lines

조회 수: 167 (최근 30일)
Jhangir
Jhangir 2013년 10월 9일
답변: Steven Lord 2024년 1월 27일
For example I want to disp('shdujfhdkjshfkjsdhkjfhkjdshfkjhsdkjfhkjsdhkjfhkjdshkfhskdhfkshdkjfhskjfdhs') but I dont want it all in one line because it continues off the screen in the command box, how do I create multiple lines?

답변 (5개)

Walter Roberson
Walter Roberson 2013년 10월 9일
disp(sprintf('shdujfhdkjshfkjsdhkjfhkjdshfkjhsdkjfhkjsdhkjfhkjdshkfhskdhfkshdkjfhskjfdhs'))
now at each place you want it broken, insert the two-character sequence \n
disp(sprintf('shdujfhdkjshfkjs\ndhkjfhkjdshfkjhsdkjfhkjsdhk\njfhkjdshkfhskdhfkshdkjfhskjfdhs'))
  댓글 수: 1
Jan
Jan 2013년 10월 9일
The linebreak in the 2nd example comes from the display in the forum. In the real code the line is continued and not distributed over several lines.

댓글을 달려면 로그인하십시오.


Simon
Simon 2013년 10월 9일
strvcat({'shdujfhdkjshfkjsdhkjfhkjdshfkj', ...
'hsdkjfhkjsdhkjfhkjdshkfhskdhfk', ...
'shdkjfhskjfdhs'})

Jan
Jan 2013년 10월 9일
disp(['shdujfhdkjshfkjsdhkjfhkjdshfkj', ...
'hsdkjfhkjsdhkjfhkjdshkfhskdhfk', ...
'shdkjfhskjfdhs'])
  댓글 수: 6
Walter Roberson
Walter Roberson 2019년 4월 1일
I suggest you learn to use sprintf(). But in the mean time, generally you would use something like
txt = {['y=', num2str(m,2), 'x', '+', num2str(c,2)], ...
['SSE=', num2str(sse,2) ' RMSE=', num2str(rmse,2) ' R^2=', num2str(rsquare,2)], ...
['n=', num2str(numel(x),2), ' p=', num2str(p_val,2)] };
Each group inside [] goes together to form one line, and the different groups will get placed on different lines.
Adriana Velasquez
Adriana Velasquez 2019년 4월 2일
wow excellent! Thanks a lot Walter! that helps me inmensely in "in the mean time". I know, I have to learn a lot, I just wanted to save some time using Matlab for my stats instead for doing 150 regressions manually! Thanks!
GLM of raw Macroalgae coverage.png

댓글을 달려면 로그인하십시오.


pathakunta
pathakunta 2024년 1월 26일
now at each place you want it broken, insert the two-character sequence \n Disp(sprintf('shdujfhdkjshfkjs\ndh
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 1월 26일
This is the solution I suggested 10 years ago.

댓글을 달려면 로그인하십시오.


Steven Lord
Steven Lord 2024년 1월 27일
Another way to do this is to use textwrap, particularly if you're planning to use this to put the text in a control in an app.
s = 'shdujfhdkjshfkjsdhkjfhkjdshfkjhsdkjfhkjsdhkjfhkjdshkfhskdhfkshdkjfhskjfdhs'
s = 'shdujfhdkjshfkjsdhkjfhkjdshfkjhsdkjfhkjsdhkjfhkjdshkfhskdhfkshdkjfhskjfdhs'
t = textwrap(string(s), 40)
t = 2×1 cell array
{'shdujfhdkjshfkjsdhkjfhkjdshfkjhsdkjfhkjs'} {'dhkjfhkjdshkfhskdhfkshdkjfhskjfdhs' }
If you need this to be a character vector instead of a cell array of character vectors, you could use strjoin.
s2 = strjoin(t, newline)
s2 =
'shdujfhdkjshfkjsdhkjfhkjdshfkjhsdkjfhkjs dhkjfhkjdshkfhskdhfkshdkjfhskjfdhs'

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by