Let's suppose a simple file "test.m" with the following code:
obj = app1;for i = 1:10 fprintf('\ni = %d\n', i); if i==1 str = num2str(i); else str = sprintf('%s\n%s', str, num2str(i)); end obj.writeText('1', str); % line 10
obj.TextArea_2.Value = str; % line 11
end
"app1.mlapp" is a GUI class made through appdesigner. In its code I defined two textareas:
% Create TextArea_1
app.TextArea_1 = uitextarea(app.UIFigure); app.TextArea_1.Position = [47 187 259 150];% Create TextArea_2
app.TextArea_2 = uitextarea(app.UIFigure); app.TextArea_2.Position = [335 187 259 150];
and defined a public function:
methods (Access = public) function writeText(app, ind, text) if ind <= length(2) ta = ['TextArea_', ind]; ta.Value = text; end endend
only line 11 prints in in TextArea_2. So, why doesn't line 10 print in TextArea_1 ???
thanks in advance.
PS: in the attached file "GUI-example.zip", it's included the 2 files "app1.mlapp" and "test.m".
Best Answer