Display mutiple lines in Text area in Matlab App designer

49 ビュー (過去 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 Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by