MATLAB Answers

How to display a long string in multiple lines?

32 views (last 30 days)
I have a cell called C containing many strings, of which some are very long and it's hard to view in one line. I want to be able to call these strings and print them but in multiple lines: str=C{n,1}; fprintf('%s\n',str)
How I would be able to do that? Any help would be greatly appreciated.

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 17 Sep 2018
PerLine = 80;
pattern = sprintf('.{1,%d}', PerLine);
str = regexp(C{n,1}, pattern, 'match');
fprintf('%s\n', str{:});

  1 Comment

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Products


Release

R2018a