How to display constant with caption in separate window

So I have this function:
save('LenaInitial.txt','SaveMatr');
s = dir('LenaInitial.txt');
filesizeini = s.bytes;
And I need to display filesizeini with some caption in separate window. Functions like disp or text are not suitable.

2 Comments

Are you displaying this text in a figure? in the command window? in a text field within an app?
And why aren't disp and text() suitable?
I need to display it in separate window like picture or plot. Not command window. Hence I need something else besides disp(). And text() displays this constant in a window with picture even if I creating new figure.

Sign in to comment.

 Accepted Answer

You can only plot text on axes (not on the figure background). However, the axes can be invisible so it appears as if the text is on the figure. Here's a demo.
fh = figure();
% add axis to bottom, left corner
ah = axes(fh,'position',[0,0,.3,.1]);
% add text
x.bytes = 9000;
filesizeini = s.bytes;
textStr = sprintf('filesize = %d bytes', s.bytes);
text(ah,.2,.2,textStr,'HorizontalAlignment', 'left', 'VerticalAlignment', 'bottom')
% Turn off axis
ah.Visible = 'off';
Note that can combine the last line of code with the axes() line like this :
ah = axes(fh,'position',[0,0,.3,.1],'Visible','off');

6 Comments

thank you! thats what I've needed.
only one question for you: is there any way to combine several functions like mine of showing file size in one figure?
Glad it helped.
I'm not sure I understand your follow-up question. What functions would you like to combine?
functions like these
s = dir('LenaInitial.txt');
filesizeini = s.bytes;
s = dir('LenaDCTZag.txt');
filesizezag = s.bytes;
s = dir('LenaCompressed_3ch.txt');
filesizecompresed = s.bytes;
ratio = filesizeini/filesizecompresed;
ratio2 = filesizezag/filesizecompresed;
combined in one figure
You can add multiple lines of text by inserting line breaks with \n
textStr = sprintf('filesizeini = %d bytes\nfilesizezag = %d\nratio = %.2f\n ratio2 = %.2f',...
filesizeini,filesizezag,ratio,ratio2);
Then you'll have to move the position of the text upward so that it doesn't go off the figure window. You may have to increase the size of the axis, too.
Thank you very much! This was helpful

Sign in to comment.

More Answers (1)

Do you want to display a small dialog box with the text? If so use the msgbox or uialert functions.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!