How to save/print multiples images using a for loop?
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
KALYAN ACHARJYA
2019 年 2 月 2 日
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 件のコメント
Image Analyst
2019 年 2 月 7 日
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
2019 年 2 月 2 日
See my attached demo. Adapt as needed (like to get rid of the part where I make the plots into a movie.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Convert Image Type についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!