Display mutiple lines in Text area in Matlab App designer

21 views (last 30 days)
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 Comments
Monica Roberts
Monica Roberts on 9 May 2022
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

Sign in to comment.

Answers (1)

Rik
Rik on 6 May 2022
Edited: Rik on 9 May 2022
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 Comments
Emerson Nithiyaraj
Emerson Nithiyaraj on 9 May 2022
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 on 9 May 2022
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

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!