Azzera filtri
Azzera filtri

Opening and writing to a text window with scroll bar.

18 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Matt Fig
Matt Fig il 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 Commento
Donald Jones
Donald Jones il 15 Gen 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Printing and Saving in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by