Opening and writing to a text window with scroll bar.

14 views (last 30 days)
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.

Accepted Answer

Matt Fig
Matt Fig on 29 Mar 2011
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 Comment
Donald Jones
Donald Jones on 15 Jan 2022
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

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!