Opening and writing to a text window with scroll bar.

16 ビュー (過去 30 日間)
Truman
Truman 2011 年 3 月 29 日
コメント済み: Donald Jones 2022 年 1 月 15 日
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.

採用された回答

Matt Fig
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
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 ExchangePrinting and Saving についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by