MATLAB: Problem with multi-line in TextEdit box

edit textmulti-line

Hi, I cannot find a way to display the text in multiple lines in text edit box. I read that I all I need is to set property Max to be larger than Min (e.g. Max = 2), but this does not do the trick. For test purpose I have simple GUI, with only one text edit box and one button. "Pushbutton1_Callback" function executes the following code:
for i =1 :100
set(handles.edit1,'String', [num2str(i), ' test'] );
pause(0.1);
end
However, all i get on the box is single line. How can I fix this to obtain multiple lines like this:
1 test
2 test
3 test ….
Thank you!

Best Answer

stani7062 - in your above for loop, you are replacing the String property for the text box on each iteration of the loop. Rather than replacing, you should be appending. Try the following instead
for i =1 :100
strData = get(handles.edit1,'String');
if isempty(strData)
strData = {};
end
strData = [strData; [num2str(i), ' test']];
set(handles.edit1,'String',strData);
end
In the above, we check to see if the current data, stdData, is empty or not. If so, then we set it to an empty cell array so that we can append the new strings to it (with the semi-colon, we ensure that each new string is appended as a new line or row).