Hi,
I am using the below subroutine inside for loop to save images during every itertaion. Here, I would like to save the images in new folder. Please help me with this...
if (f>=1) && (f<=9)
saveas(gcf, sprintf('S0000%d', f), 'bmp')
elseif (f>=10) && (f<=99)
saveas(gcf, sprintf('S000%d', f), 'bmp');
elseif (f>=100) && (f<=999)
saveas(gcf, sprintf('S00%d', f), 'bmp');
else
saveas(gcf, sprintf('S0%d', f), 'bmp');
end

6 commentaires

Turbulence Analysis
Turbulence Analysis le 26 Sep 2020
Hi,
Tried as follows, bur it's not saving any images
folder = 'D:\CH\new\';
for f = 1:1:2
if (f>=1) && (f<=9)
fname_strt = 'B0000' ;
elseif (f>=10) && (f<=99)
fname_strt='B000';
elseif (f>=100) && (f<=999)
fname_strt='B00';
else
fname_strt='B0';
end
fname_end = num2str(f);
fname = strcat(fname_strt,fname_end,'.im7');
I=loadvec(fname);
x=(I.x);
y=(I.y);
h = figure (2);
G= imagesc(x,y,(I.w'));
ax=gca;
%G.AlphaData = 0.9;
colormap(bone);
set(gca, 'YDir','normal')
axis equal;
thisBaseFileName = sprintf('S%4.5d.png', f);
fullFileName = fullfile(thisBaseFileName);
fprintf('Saving %s\n', fullFileName);
%clf
%DISP off;
end
Missing on
saveas(gcf, fullFileName)
Turbulence Analysis
Turbulence Analysis le 26 Sep 2020
Hi,
Thanks, Actually, I figured that, added saveas(gcf, fullFileName). Now, it saves images, but it saves in the same folder where i am reading the input file
for example if i am reading the file from 'D:\CH\', the processed file should save inside 'D:\CH\new\'....
prefix = '\\new\\';
thisBaseFileName = sprintf('%sS%4.5d.png',prefix, f);
Have two folders:
inputFolder = 'D:\CH\';
outputFolder = 'D:\CH\new\';
if ~isfolder(outputFolder)
mkdir(outputFolder);
end
Then in the loop
fname = fullfile(inputFolder, fname); % Create full input filename.
thisBaseFileName = sprintf('S%4.5d.png', f); % Base output file name.
fullFileName = fullfile(outputFolder, thisBaseFileName); % Create full output filename in different folder.
Not sure why you removed the folder from my call to fullfile() in my answer. You should not have done that. fullfile() needs both a folder and a base file name.
Turbulence Analysis
Turbulence Analysis le 27 Sep 2020
Thanks it worked perfectly..
Furthermore, regarding my previous query on "having two colorbars in the contours for the images read in .im7 format". I have sent the .im7 files and loadvec function as per your request. Is .im7 readable now ???

Connectez-vous pour commenter.

 Réponse acceptée

Image Analyst
Image Analyst le 26 Sep 2020

1 vote

Do it this way:
folder = pwd % Wherever you want...
for k = 1 : 1234
thisBaseFileName = sprintf('S%4.4d.png', k);
fullFileName = fullfile(thisBaseFileName);
fprintf('Saving %s\n', fullFileName);
% saveas() of exportgraphics()
end

Plus de réponses (1)

Mario Malic
Mario Malic le 26 Sep 2020

0 votes

saveas(gcf, sprintf('/folder/S0000%d.bmp', f))

2 commentaires

Turbulence Analysis
Turbulence Analysis le 26 Sep 2020
Is 'f' here represents the folder destination ??
Mario Malic
Mario Malic le 26 Sep 2020
No, /folder/ is, but use Image Analyst's solution, it's much better than what you have.

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by