Display long strings that include newlines in a table

조회 수: 13 (최근 30일)
John Dzielski
John Dzielski 2023년 12월 1일
답변: John Dzielski 2023년 12월 4일
I want to create and display a table in a live script. One of the colums is a string. In some cases, this string is very long, and the column is much wider than the viewable area of the script. I have inserted newlines in the string to insure there are no more than say N characters between each newline, but when I display the string in a table the cell containing the string contains only a single row of characters with a small character that looks like a carriage return at the location of each new line. Is there a way to display multi-line strings in a table?

채택된 답변

John Dzielski
John Dzielski 2023년 12월 4일
The reason behind the question was that I want to display the information inside of a LiveScript in a "nicer" way that simply printing it out. It turns out that if you allow the live script to show the table (variable name not followed by a ';'), then hover the pointer over the cell containing the long text, the text will display the whole text in multi-line format. While this doesn't do exactly what I want, it is an acceptable solution.
Using disp() does not achieve this result when displaying a table. If the table is dipslayed from within a function call (table name w/o ';'), this also does not have the desired effect. The result of this is different from within the Live Script.

추가 답변 (1개)

Matt J
Matt J 2023년 12월 1일
편집: Matt J 2023년 12월 1일
I don't think there's a way. But you could write to an Excel file (e.g., with writetable) where multiline cells are possible.
>> s="aaa"+sprintf('\n')+"bb"
s =
"aaa
bb"
>> T=table(s)
T =
table
s
_________
"aaa↵bb"
>> writetable(T,'tst.xls')
  댓글 수: 1
Matt J
Matt J 2023년 12월 1일
편집: Matt J 2023년 12월 1일
There are also ways to use actxserver to open/close/maximize an Excel file from Matlab, if you wanted to use Excel as a surrogate display window.

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

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by