Filter löschen
Filter löschen

Update string with new line in edit Field (text) in mlapp

26 Ansichten (letzte 30 Tage)
ML_Analyst
ML_Analyst am 5 Dez. 2023
Kommentiert: Voss am 7 Dez. 2023
I have a GUI with a edit text box which I will update via my script, but I want to add newlines and the edit text box should update with new lines as I have updated via the script. My code snippet is below
Text_to_update= This is sample testing” + newline + newline + “Results are stored in the output path”;
app.NewEditField.Value= Text_to_update;
But I cannot see the text displayed in 2 lines (with one line space in between) in the Edit Tex field ,it is just displayed in straight line. Could someone help here ?
  3 Kommentare
ML_Analyst
ML_Analyst am 7 Dez. 2023
Tried this.. but doesn’t work too ,also I have some variables in between too
Voss
Voss am 7 Dez. 2023
From uieditfield documentation (under Value property):
"If you want to allow multiple lines of text, use a text area component instead of an edit field."

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 5 Dez. 2023
Yeah, kind of weird. But I found that if you make it a Text instead of an Edit box, it will work and show up on multiple lines:
folder = pwd;
selectedFileName = 'whatever.png';
app.TextArea.Value = sprintf('%s\n\n%s', folder, selectedFileName);
  2 Kommentare
ML_Analyst
ML_Analyst am 7 Dez. 2023
Thanks , but for my use case thinking it’s better to use edit text field
Image Analyst
Image Analyst am 7 Dez. 2023
Why? I think not having line feeds in the edit text box may be a bug. You can assign them but it just doesn't show up on separate lines. If you get the values:
% Button pushed function: Button2
function Button2Pushed(app, event)
sText = app.TextArea.Value % Returns cell array.
sEdit = app.EditField.Value % Returns character array.
end
You'll see the difference is the text box value comes back as a cell array with each line of the text box as one cell, and the edit text comes back as a character array.
You can still allow the user to edit the text box and change it, you just have to deal with their input as a cell array, which is no big deal. So for all intents and purposes it seems they are pretty similar and using a text box to capture user input should work just fine. Why do you think it won't???

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by