display data in text field MATLAB app designer

How can I display my data into the test field. My data is in the loop as shown in the code. I want to display all data in text field( any other field can be suggested).
function ButtonPushed(app, event)
for i = 1:10
disp(' ')
value1=['Sess (', int2str(i), '/' int2str(i+1) '):']
app.TextArea.Value=value1;
end
end
function TextAreaValueChanged(app, event)
value = app.TextArea.Value;
end

 Accepted Answer

What is the point of the disp() there?
Inside the loop, you are changing all of the value of the text area, overwriting what was previously there, and you do not have any kind of pause to allow the person to read the text.
If you want to display all of the data, have you considered building a string() array? Possibly even without a loop?
i = (1:10).';
s = "Sess (', " + i + "/" + (i+1) + ")";
app.TextArea.Value = s;

7 Comments

Thanks for the help Walter, disp() was just for matlab command prompt, actually my task is to display it in loop without overwriting. Can you help in displaying in the loop, if table or any other field help?
Are you specifically required to use a loop?
Are you expected to have it display the first line, then pause briefly, then add another line, then pause briefly, then add the third line, and so on?
app.TextArea.Value = strings(0);
for i = 1 : 10
s = "Sess (', " + i + "/" + (i+1) + ")";
app.TextArea.Value(i) = s;
pause(0.05);
end
Yes I have to use the loop and display it as you decribed like first line then second.
I have tried ur code but it is giving me this error.
'Value' must be a character vector, or a 1-D array of the following type: cell array of character vectors, string, or categorical.
app.TextArea.Value = "";
for i = 1 : 10
s = "Sess (" + i + "/" + (i+1) + ")";
app.TextArea.Value(i) = s;
pause(0.05);
end
MakM
MakM on 10 Apr 2022
Edited: MakM on 10 Apr 2022
Still the error.
Unable to perform assignment because value of type 'string' is not convertible to 'cell'.
app.TextArea.Value = {''};
for i = 1 : 10
s = "Sess (" + i + "/" + (i+1) + ")";
app.TextArea.Value{i} = char(s);
pause(0.05);
end
Thanks Walter, It works :)

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 10 Apr 2022

Commented:

on 10 Apr 2022

Community Treasure Hunt

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

Start Hunting!