How to use \n and \t with sprintf to set the string of a ui control

1 回表示 (過去 30 日間)
Danielle
Danielle 2017 年 11 月 1 日
回答済み: Stephen23 2017 年 11 月 1 日
I am trying to take what was originally printed using fprintf in the command window and have it print within a static textbox using sprintf. However, I cannot get the '\n' and '\t' commands to print multiple lines of information in an organized way. Does anyone know how to do this?
I am concatenating different lines by saying temp = sprintf('Hello'); x = strcat(x, temp); temp = sprintf('How is your day?'); x = strcat(x, temp);
set(DISPLAY.htext, 'String', x);

回答 (2 件)

KL
KL 2017 年 11 月 1 日
You could use a cell array,
C = {'Hello!'; 'How are you?'};
x = sprintf('%s\n%s',C{1,1},C{2,1});

Stephen23
Stephen23 2017 年 11 月 1 日
The UIcontrol properties help page explains how to define the string value to get multiple lines:
The exact method varies slightly between control types, but in general you can't go wrong with a cell array of char vectors: each char vector will be one line in the uicontrol.

カテゴリ

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