Adding new line in text property

6 ビュー (過去 30 日間)
Wilfried
Wilfried 2025 年 3 月 26 日
回答済み: Wilfried 2025 年 3 月 28 日
How can I add a new line before each paragraph in the Text property of the Header in a getHeaderImpl method with system object?
I tried (\n) , but it did not work.
  2 件のコメント
Walter Roberson
Walter Roberson 2025 年 3 月 26 日
Did you try using the newline function, or adding char(10) ?
A = "this" + newline + "that"
A =
"this that"
B = ['this' char(10) 'that']
B =
'this that'
Wilfried
Wilfried 2025 年 3 月 27 日
編集済み: Wilfried 2025 年 3 月 28 日
Yes. It did not work. There is no text displayed when I tried that.
Thanks for the suggestion, it works without adding the + sign. For example: 'Text', ['My first paragraph'
newline 'My second paragraph']; ==> this works, but if i add + after newline, it modify the text and does not provide a newline.

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

採用された回答

Wilfried
Wilfried 2025 年 3 月 28 日
Use newline without comma or + sign at the start of each new paragraph.

その他の回答 (1 件)

Marie Anna NOVIELLO
Marie Anna NOVIELLO 2025 年 3 月 27 日
Try to use the newline function:
function header = getHeaderImpl(obj)
header = [newline, 'First paragraph', newline, newline, 'Second paragraph', newline, newline, 'Third paragraph'];
end
or
Try to use the sprintf function:
function header = getHeaderImpl(obj)
header = sprintf('\n%s\n\n%s\n\n%s', 'First paragraph', 'Second paragraph', 'Third paragraph');
end
  1 件のコメント
Wilfried
Wilfried 2025 年 3 月 28 日
newline works with no comma. thanks.

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

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by