Display mutiple lines in Text area in Matlab App designer

21 次查看(过去 30 天)
I have attached my code below.
for a = 1:length(my_Files)
baseFileName1 = my_Files(a).name;
fullFileName1 = fullfile(myDir, baseFileName1);
i = imread(fullFileName1);
if max(max(i)) == 255
char6 = sprintf('%s has the presence of tumour \n',baseFileName1);
app.TextArea3.Value = char6;
c=c+1;
end
end
I want the text area to display multiple lines like,
Image 1 has the presence of tumour
Image 2 has the presence of tumour
Image 3 has the presence of tumour
Image 4 has the presence of tumour .......
But I get only the last image name in the text area and i coudnt get all the image names as multiple lines.
Image 127 has the presence of tumour
I need someone's help to sort this out.
Thanks in advance.
  6 个评论
Monica Roberts
Monica Roberts 2022-5-9
I see 2 problems here. 1. You are clearing out char6 on every loop iteration. 2. If a is greater than 1, char6 has a bunch of empty cells. To see what I mean, try this code in the command window:
temp{4,1} = 'Example text'
You can make the variable before the for-loop and then tack on text to the end:
char6 = {};
for a = 1:length(my_Files)
baseFileName1 = my_Files(a).name;
fullFileName1 = fullfile(myDir, baseFileName1);
i = imread(fullFileName1);
if max(max(i)) == 255
char6{end+1,1} = char(sprintf('%s has the presence of tumour \n',baseFileName1));
app.TextArea3.Value = char6;
c=c+1;
end
end

请先登录,再进行评论。

回答(1 个)

Rik
Rik 2022-5-6
编辑:Rik 2022-5-9
You are replacing the text every iteration. What you need to do is concatenate them.
Start with an empty line before the loop, then append the new results in your loop.
Edit:
for a = 1:numel(my_Files)
baseFileName1 = my_Files(a).name;
fullFileName1 = fullfile(myDir, baseFileName1);
im = imread(fullFileName1);
char6 = '';
if max(im(:)) == 255
if isempty(char6)
char6 = sprintf('%s has the presence of tumour',baseFileName1);
else
char6 = sprintf('%s\n%s has the presence of tumour',char6,baseFileName1);
end
app.TextArea3.Value = char6;
c=c+1;
end
end
  2 个评论
Emerson Nithiyaraj
I tried this but, I still get only the last image name in the text area. I didnt get multiple image names in the text area.
Rik
Rik 2022-5-9
You can also use a cellstr instead of a char vector:
for a = 1:numel(my_Files)
baseFileName1 = my_Files(a).name;
fullFileName1 = fullfile(myDir, baseFileName1);
im = imread(fullFileName1);
char6 = '';
if max(im(:)) == 255
if isempty(char6)
char6 = {sprintf('%s has the presence of tumour',baseFileName1)};
else
char6{end+1,1} = sprintf('%s\n%s has the presence of tumour',char6,baseFileName1);
end
app.TextArea3.Value = char6;
c=c+1;
end
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by