Line break in "question dialog"

100 ビュー (過去 30 日間)
Jorge
Jorge 2011 年 1 月 31 日
編集済み: Walter Roberson 2025 年 2 月 17 日 17:27
Hi. I'm trying to introduce a line break in question dialog box in the qstring. I've used '\n' but it gives me error. Also I've used the three points (...) but it happened the same. Is the line break accepted in the question dialog box? Thanks

回答 (5 件)

Martijn
Martijn 2011 年 1 月 31 日
Functions like INPUTDLG and MSGBOX do not interpret '\n' characters; SPRINTF does however. So using SPRINTF should do the trick:
msgbox(sprintf('Line 1\nLine 2'))

Doug Eastman
Doug Eastman 2011 年 1 月 31 日
Another approach is to use a cell array:
questdlg({'Text on line 1','Text on line 2'})

Paulo Silva
Paulo Silva 2011 年 1 月 31 日
questdlg(['Text on line 1' sprintf('\n') 'Text on line 2'])

Axel Montano
Axel Montano 2020 年 5 月 9 日
編集済み: Axel Montano 2020 年 5 月 9 日
'String',sprintf('Line 1\nLine 2'));
This is what I used when running a dialog box.
Here is the whole code to make it easier for anyone wanting to play around with a dialog box.
Goodluck!
d = dialog('Position',[1000 600 400 300],'Name','Written by: ME!');
txt = uicontrol('Parent',d,...
'Style','text',...
'Position',[100 200 210 40],...
'String',sprintf('Line 1\nLine 2\nLine 3'));
btn = uicontrol('Parent',d,...
'Position',[150 20 100 40],...
'String','Close dialog box',...
'Callback','delete(gcf)');
  2 件のコメント
Axel
Axel 2023 年 3 月 23 日
This is an old post, however for any future reference. The newline command can be used to perform this task properly.
"You selected to solve a single load transmission line problem." newline "test line of text"
Walter Roberson
Walter Roberson 2025 年 2 月 17 日 17:27
You would use
"You selected to solve a single load transmission line problem." + newline + "test line of text"

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


sr123
sr123 2025 年 2 月 17 日 13:13
編集済み: Walter Roberson 2025 年 2 月 17 日 17:27
Linking to a comment at the bottom of this thread which seems to me the best solution for this problem on newer releases:

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by