Opening and writing to a text window with scroll bar.
14 次查看(过去 30 天)
显示 更早的评论
This is a very simple question and I feel a bit silly asking. However, I cannot find any information in the documentation. I have an algorithm that is generating estimates on multiple scans of data. I would like to print out the numerical results but do not want to do in in the command window. I would like to open a text window with the ability to scroll and write the information to this window. Any pointers would be appreciated.
0 个评论
采纳的回答
Matt Fig
2011-3-29
You could certainly do this with a uicontrol object. I don't know how convenient it would be to do it this way, I guess it would depend on how large your outputs might be. Here is a function which creates such an textbox.
function [S] = txt_update
% Creates a textbox.
S.fh = figure('units','pixels',...
'position',[40 40 240 940],...
'menubar','none',...
'resize','off',...
'numbertitle','off',...
'name','Program output');
S.tx = uicontrol('style','edit',...
'units','pix',...
'position',[10 60 220 830],...
'backgroundcolor','w',...
'HorizontalAlign','left',...
'min',0,'max',10,...
'enable','inactive');
.
.
Now, do this, for example:
S = txt_update; % Create the textbox.
for ii = 1:50
A = rand(ceil(rand*2),ceil(rand*3)); % Update with numeric data.
set(S.tx,'string',cat(1,get(S.tx,'string'),{num2str(A)}))
pause(.1) % Simulate some long calculation.
end
for jj = 1:50
B = char(rand(1,9)*10+110); % Update with character data.
set(S.tx,'string',cat(1,get(S.tx,'string'),{B}))
pause(.1) % Simulate some long calculation.
end
To see the most recent data at the top, reverse the second and third arguments to the CAT function.
1 个评论
Donald Jones
2022-1-15
Matt,
I like your code -- it almost does the job for me. But I also want to make the window and text box resizable. I can set "resize" to "on" in the figure statement, which lets the overall window be resizable, but it doesn't enable me to make the text box resizable at run time. Also, is there a way to allow the user to save the text in the text box to a file?
Thanks,
Don Jones
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!