[MATLAB GUI] How can I add a string to the last line in multiline EditText?

2 vues (au cours des 30 derniers jours)
Luong Son
Luong Son le 24 Avr 2014
Commenté : per isakson le 26 Avr 2014
  • Hi all,
  • I often use this way to add a string to the last line in multiline editText:
  • Example: The before editText: (handles.txtLine)
  • "line 1
  • line 2
  • line 3"
  • and i want to add string "line 4" to it. So i do:
  • msg = get(handles.txtLine,'string');
  • msg_i = sprintf('
  4 commentaires
Sara
Sara le 24 Avr 2014
Do you get any particular error in doing it your way? Can you post the exact code you are using?
Luong Son
Luong Son le 25 Avr 2014
Hi, My question is below! Can u help me resolve :D! Thanks advance

Connectez-vous pour commenter.

Réponses (2)

per isakson
per isakson le 24 Avr 2014
Modifié(e) : per isakson le 24 Avr 2014
To me it isn't clear what your problem is. Anyhow there is no alternative to
set( h, 'String', string_values )
...
string_values = get( h, 'String' );
% add new line to string_value and
set( h, 'String', string_values )
However, I find it more convenient to use a cell array of strings for string_values. Doc says: For multiple line editable text [...] line breaks occur [...] each cell of a cell array of strings

Luong Son
Luong Son le 24 Avr 2014
Modifié(e) : Luong Son le 24 Avr 2014
  • I have 2 buttons: Receive and Send.
  • The first, I click button Receive. EditText become:
Receive: 2
Receive: 1
  • The EditText will be update constantly:
Receive: i
...
Receive: 2
Receive: 1
  • Next, I click button Send. I want my EditText become:
Receive: 3
Send: OK
Receive: 2
Receive: 1
  • In fact, when I click button Send, String "Send: OK" was added, but it disappear immediately. And I can't understand why it disappear! Can u help me resolve it?P/S: My English is not well. Thanks for reading.
  1 commentaire
per isakson
per isakson le 26 Avr 2014
I stepped through your code but gave up. Obviously the string, "Send: OK", is not handled as you (and I) expect by guidata and handles.Mes.
First step might be to rename
pushbutton1_Callback
to something that includes the string
Receive

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by