saving images in loop

4 ビュー (過去 30 日間)
HYZ
HYZ 2020 年 5 月 28 日
コメント済み: HYZ 2020 年 5 月 28 日
Hi,
frateMaps is a cell array. I would like to save images for each vector in frateMaps.
I could see the images for each loop but the images are not saved. I would like to save each image with labelling 1, 2, 3 etc based on loop number.
I tried to modify second parts of code but didn't work. could anyone please advise how to save? thank you.
for i = 1: length(fwdposx)
figure('color','w')
drawfield(frateMaps{i},'jet',max(max(frateMaps{i})));
titleStr = sprintf('%s%s%3.1f%s',tFileList{jj}(1:end-2),' Peak = ',max(max(frateMaps{i})),' Hz');
title(titleStr,'FontSize',20,'Interpreter','none');
axis off
axis image
drawnow;
ratemapImage= strcat(sessions{ii},[funcName,' Map Image ',date],'\',tFileList{jj}(1:end-2),'_forward rateMap_run');
imageStore(gcf,6,ratemapImage,150);%tif format, 150dpi
imageStore(gcf,3,ratemapImage,150);%eps format, 150dpi
close;
end

回答 (1 件)

KSSV
KSSV 2020 年 5 月 28 日
for i = 1: length(fwdposx)
figure('color','w')
drawfield(frateMaps{i},'jet',max(max(frateMaps{i})));
titleStr = sprintf('%s%s%3.1f%s',tFileList{jj}(1:end-2),' Peak = ',max(max(frateMaps{i})),' Hz');
title(titleStr,'FontSize',20,'Interpreter','none');
axis off
axis image
drawnow;
saveas(gcf,['image',num2str(i),'.png'])
ratemapImage= strcat(sessions{ii},[funcName,' Map Image ',date],'\',tFileList{jj}(1:end-2),'_forward rateMap_run');
imageStore(gcf,6,ratemapImage,150);%tif format, 150dpi
imageStore(gcf,3,ratemapImage,150);%eps format, 150dpi
close;
end
  1 件のコメント
HYZ
HYZ 2020 年 5 月 28 日
sorry .. images are still not saved. if I put loop by loop (e.g. frateMaps{1}, etc) each image is saved.
imageStore is own function as below. I didn't write the code and juz trying to modify what I want so I am a bit lost how to modify to save all images. thanks!
% Function for storing figures to file
% figHanle Figure handle (Ex: figure(1))
% format = 1 -> bmp (24 bit)
% format = 2 -> png
% format = 3 -> eps
% format = 4 -> jpg
% format = 5 -> ai (Adobe Illustrator)
% format = 6 -> tiff (24 bit)
% figFile Name (full path) for the file
% dpi DPI setting for the image file
function imageStore(figHandle,format,figFile,dpi)
% Make the background of the figure white
set(figHandle,'color',[1 1 1]);
dpi = sprintf('%s%u','-r',dpi);
switch format
case 1
% Store the image as bmp (24 bit)
figFile = strcat(figFile,'.bmp');
print(figHandle,dpi, '-dbmp',figFile);
case 2
% Store image as png
figFile = strcat(figFile,'.png');
print(figHandle,dpi,'-dpng',figFile);
case 3
% Store image as eps (Vector format)
figFile = strcat(figFile,'.eps');
print(figHandle,dpi,'-depsc',figFile);
case 4
% Store image as jpg
figFile = strcat(figFile,'.jpg');
print(figHandle,dpi, '-djpeg',figFile);
case 6
% Store image as tiff (24 bit)
figFile = strcat(figFile,'.tif');
print(figHandle,dpi, '-dtiff',figFile);
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by