Borrar filtros
Borrar filtros

How to save each data from for loop

1 visualización (últimos 30 días)
neha gautam
neha gautam el 30 de Abr. de 2018
Comentada: dpb el 1 de Mayo de 2018
I have a for loop(last for loop), but every character overwrites and I have only the final data left.
[L Ne]=bwlabel(imagen);
%%Measure properties of image regions
propied=regionprops(L,'BoundingBox');
hold on
%%Plot Bounding Box
for n=1:size(propied,1)
rectangle('Position',propied(n).BoundingBox,'EdgeColor','g','LineWidth',2)
end
hold off
pause (1)
%%Objects extraction
figure(3)
for n=1:Ne
[r,c] = find(L==n);
n1=imagen(min(r):max(r),min(c):max(c));
%imshow(~n1);
pause(0.5)
end
  2 comentarios
Ameer Hamza
Ameer Hamza el 30 de Abr. de 2018
What is imagen()? Is it your own function. In any case refer to my answer below.
neha gautam
neha gautam el 30 de Abr. de 2018
imagen() is a variable which store the matrix of image.

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 30 de Abr. de 2018
Easiest solution is to save each in cell array since the subsets can all be differing sizes can't just store as planes in 3D array...
IMAGES=cell(Ne,1); % create a cell array of proper size
for n=1:Ne
[r,c] = find(L==n);
IMAGES(i)={imagen(min(r):max(r),min(c):max(c))}; % store each 2D array in nth cell
%imshow(IMAGES{n});
pause(0.5)
end

Más respuestas (1)

Ameer Hamza
Ameer Hamza el 30 de Abr. de 2018
Editada: Ameer Hamza el 30 de Abr. de 2018
Change your last for loop as follow
n1 = []
for n=1:Ne
[r,c] = find(L==n);
n1 = [n1 imagen(min(r):max(r),min(c):max(c))];
%imshow(~n1);
pause(0.5)
end
n1 will save all the values.
  8 comentarios
neha gautam
neha gautam el 1 de Mayo de 2018
Thank you so much for your valuable advice. I would like to go with your suggestions.
dpb
dpb el 1 de Mayo de 2018
You have my permission to do so, yes... :)
Good plan to follow "best practices" in avoiding these kinds of what_seem_so_easy_to_do techniques, but the short-term gratification leads to longer-term misery when get to anything but the most trivial of applictions--best to learn to avoid altogether while learning; then with time one can recognize when it is time to break the rule for a specific purpose (altho that's not that common, it does occur).

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by