Display mutiple lines in Text area in Matlab App designer

조회 수: 56 (최근 30일)
Emerson Nithiyaraj
Emerson Nithiyaraj 2022년 5월 6일
댓글: Emerson Nithiyaraj 2022년 5월 18일
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
Emerson Nithiyaraj
Emerson Nithiyaraj 2022년 5월 18일
thank you so much @Monica Roberts. Your sugggestion worked out exactly.

댓글을 달려면 로그인하십시오.

답변 (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
Emerson Nithiyaraj 2022년 5월 9일
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에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by