How to save/print multiples images using a for loop?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
so, I'm loading some files within a for loop and I want to print a image for each iteration of the for loop:
folder= dir ('*.mat')
for id=1:length (folder)
load (folder(id).name) %this load the files one by one so I can create an image for each iteration
for ix= 1:rep
hold on
scatter (vec, x_mean(ix, :, 1),'b','filled')
scatter (vec, x_mean(ix, :, 2),'r', 'filled')
plot (vec, rep_prom1,'b')
plot (vec, rep_prom2, 'r')
hold off
set (gca, 'Xtick', vec, 'Xticklabel', vec)
%the lines above create de image that I want for each file
%whit this I espect to get as many images as files loaded, I use 'strcat' and 'num2str' so I can save the images with differents names for each
print(strcat('Densidades Promedio. ', ' Alpha=' ,num2str(alfa), '. p=', num2str(p), '.'), '-dpng')
end
end
But when I run this code, matlab give me only one image with all of the files on it, and save multiples files with the names saved correctly, but this files are damaged and I can't open them. Any idea how can I do this?
thank you very much beforehand
0 comentarios
Respuestas (2)
KALYAN ACHARJYA
el 2 de Feb. de 2019
As you mentioned that you have already read the images using for loop.
Syntax code as follows
for k=1:k %k be numbers of images in the folder
%supoose you do the computation on images one by one and each iteration you need to save the image
%say result image name as result1
destination='D:\Kalyan Works\Matlab Work\od_region_grow_DRIONS\im'; %Complete path to save images
%here 'od_region_grow_DRIONS' folder name and im initial file name of save images in that folder
%save images as im1.png, im2.png etc
imwrite(result1,[destination,num2str(k),'.png']);
end
3 comentarios
Image Analyst
el 7 de Feb. de 2019
You said "print" - do you want to have your code print them immediately on paper in a printer?
You also said plot. What does it mean to "plot" an image (like a graph)??? Do you mean "display"?
Do you want to
- plot
- display
- save to disk
the image?
Image Analyst
el 2 de Feb. de 2019
See my attached demo. Adapt as needed (like to get rid of the part where I make the plots into a movie.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!