Display mutiple lines in Text area in Matlab App designer

46 visualizaciones (últimos 30 días)
Emerson Nithiyaraj
Emerson Nithiyaraj el 6 de Mayo de 2022
Comentada: Emerson Nithiyaraj el 18 de Mayo de 2022
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 comentarios
Monica Roberts
Monica Roberts el 9 de Mayo de 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
Emerson Nithiyaraj
Emerson Nithiyaraj el 18 de Mayo de 2022
thank you so much @Monica Roberts. Your sugggestion worked out exactly.

Iniciar sesión para comentar.

Respuestas (1)

Rik
Rik el 6 de Mayo de 2022
Editada: Rik el 9 de Mayo de 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 comentarios
Emerson Nithiyaraj
Emerson Nithiyaraj el 9 de Mayo de 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 el 9 de Mayo de 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

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by