MATLAB: Problem reading data from static text in GUIDE

guiguideprintstatic text

In my program, there is a message board that needs to be updated in real time with some messages. In this example code, i just write a 2 line message and try to read and print what is read. The way i found was:
Firts part (when i hit button A):
message1 = '123';
message2 = 'abc';
message = sprintf('%s\n%s', message1, message2);
set(handles.log,'String', message);
This part works fine. But than:
Second part (when i hit button B):
previoustext = get(handles.log, 'String');
message = sprintf('%s', previoustext);
set(handles.log,'String', message);
The result is: 1a2b3c. Like it's reading the text by columns, not by lines. Is there a way to force it to read by line? I need each message do be displayed in a different line and not erase the previous message. Thanks in advance!

Best Answer

message1 = '123';
message2 = 'abc';
message = {message1, message2};
set(handles.log, 'Max', 2, 'String', message);
You do not need to change the 'Max' to be the same as the number of strings: you only need Max to be something greater 'Min' + 1 . The default 'Max' of 1 only displays one line; a larger Max works for multiple lines.
"and not erase the previous message"
Initialize with
set(handles.log, 'Max', 2, 'String', {});
then after that, to add a line,
current = get(handles.log, 'String');
current{end+1} = message1;
current{end+1} = message2;
set(handles.log, 'String', current);