The following code I have used is for displaying the string in a static text box which is present in a GUI designed using MATLAB.Since, the output is genersted during runtime only the last line is displayed.For example,
function matchin
handles = guidata(gcbo);
set(handles.h_text,'String','performing matching...');
[image1, pathname]= uigetfile('*.bmp','Open An Fingerprint image');
Directory = fullfile ('C:','Users','ADMIN','Documents','MATLAB');
set(handles.h_text,'String','matching complete...');
D = dir(fullfile(Directory,'*.bmp'));
for i = 1:numel(D)
if isequal(image1,D(i).name)
set(handles.h_text,'String','matched');
else
set(handles.h_text,'String','not matched');
end
end
If I select the second image out of three images it is displaying
not matched
matched
not matched
in the matlab command window but, the static text box in GUI is displaying
not matched
How can I display multiple lines in the static text box?

 採用された回答

Image Analyst
Image Analyst 2013 年 4 月 1 日

1 投票

Use sprintf() to build up your string. Use the prior version of the string so you can append to it. And like Walter said, set the max property of the static text control to 2. Run this snippet for a demo:
message = '';
for k = 1 : 10
message = sprintf('%sThis is line #%d\n', message, k)
end

6 件のコメント

Padmapriya
Padmapriya 2013 年 4 月 6 日
I have changed the "for" loop with the following code
message='';
for i = 1:numel(D)
if isequal(image1,D(i).name)
message=sprintf('%s\n%s',message,matched);
set(handles.h_text,'String',message);
else
message=sprintf('%s\n%s',message,notmatched);
set(handles.h_text,'String',message);
end
end
But I am getting the error stating that
Undefined function or variable 'matched'.
Error in matchin (line 31)
message=sprintf('%s\n%s',message,matched);
Error while evaluating uicontrol Callback
Where have I gone wrong?
Padmapriya
Padmapriya 2013 年 4 月 6 日
I corrected the error myself..Thanks for your help. I am very thankful.
Alexei
Alexei 2014 年 11 月 12 日
Hi, Image Analyst. What is the meaning of setting the max property of the static text control to 2? I right clicked on it and selected the "What's this?" pop-up, but the box that came up does not actually mention static text boxes. Thank you!
Image Analyst
Image Analyst 2014 年 11 月 12 日
That lets the sentences wrap instead of being all on one long line.
Marie
Marie 2024 年 8 月 11 日
This worked great! I was wondering how I could do this if I wanted each line to start with a new phrase. I want to plot in my textbox n =1, A=3, and B=4 on seperate lines.
Image Analyst
Image Analyst 2024 年 8 月 11 日
@Marie did you try something like
app.textbox1.Value = sprintf('n=1\nA=3\nB=4');

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 4 月 1 日

0 投票

Each time through the "for i" loop, you are overwriting the existing String property with a single entry, so of course it is only displaying one entry.
In order to display multiple lines in a static text box, pass a cell array of strings as the String property. You might also need to set the Max parameter of the uicontrol to be 2.
I will leave it to you to figure out how to construct the cell array of strings you are going to set() the String property to.

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by