フィルターのクリア

How to display multiple lines as output from code in edit text field in app designer

70 ビュー (過去 30 日間)
Deepak Prakash K
Deepak Prakash K 2018 年 12 月 17 日
回答済み: Ana Gonçalves 2022 年 5 月 17 日
Hi. I'm trying to display multiple lines as output from my code in the edit text field in app designer. I tried implementing the following way (test code).
app.double_results.Value = sprintf('Max velocity can be reached but 1st gear ratio can be increased\n');
app.double_results.Value = sprintf('%s \r\n %s',app.double_results.Value,'Hi');
But the two strings were not displayed in two lines as shown below.
How should I modify the commands to display the two strings as seperate lines?
Btw, I'm using Matlab 2018a.

回答 (5 件)

Kevin Chng
Kevin Chng 2018 年 12 月 17 日
編集済み: Kevin Chng 2018 年 12 月 17 日
Hi, try this way
app.TextArea.Value = sprintf('Max velocity can be reached but 1st gear ratio can be increased\n');
app.TextArea.Value = [app.TextArea.Value;"hi"]
Accept my answer if it is working for you. Thanks
  5 件のコメント
Kevin Chng
Kevin Chng 2018 年 12 月 17 日
12.png
Nothing I have made to the text field. Above is my code for the button callback. Since I have to install R2018a, I can try to emulate the same thing in R2018a at night (My time zone is GMT + 8), then investigate why don't it working in 2018a.
Deepak Prakash K
Deepak Prakash K 2018 年 12 月 17 日
編集済み: Deepak Prakash K 2018 年 12 月 17 日
Ok thanks. Please let me know if you're able to implement it with 2018a. I shall also try to figure out a way and will let you know if something works.

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


Nathan Davey
Nathan Davey 2020 年 6 月 23 日
This also works with the number inside the curly braces being which line in the text area you want to print on.
app.MessagesTextArea.Value{1} = ['SG Output Power = ' num2str(SGPower(pwr)) 'dBm'];
app.MessagesTextArea.Value{2} = ['Peak Power Ouput = ' num2str(output_power) 'dBm'];
app.MessagesTextArea.Value{3} = ['Drain Current = ' num2str(Id) 'A'];

SnukeN3
SnukeN3 2020 年 5 月 7 日
This is how I solved this problem:
and the output:
There is a scroll bar on the left side of the TextArea to scroll through the results

António Tenreiro
António Tenreiro 2019 年 7 月 24 日
編集済み: António Tenreiro 2019 年 7 月 24 日
Hello,
TextArea.Value can be various types of variables, as long as it is, or it contains a string or a character array. Of these types, one possible is to have a cell array of character values, as stated by the TextArea Properties page.
So the code I use is the following function in the app I am designing using App Designer.
function DisplayTextArea(app,message)
app.iTextBox = app.iTextBox + 1;
app.UserTextArea.Value(app.iTextBox) = {message};
end
Each time I want to add a line in the TextArea, I add one element in the Cell array variable and insert the line in that new element.

Ana Gonçalves
Ana Gonçalves 2022 年 5 月 17 日
l1 = 'my text';
l2 = 'some text'
result = sprintf([l1 '\n' l2])

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by