saveas won't save my figure when in a for cycle
6 views (last 30 days)
Show older comments
Dear Matlab comunity,
I run into a problem with a command saveas. I have a for loop in which I create a set of surf plots, which I would like to save independently and for each cycle. When I run just the part with the surf plots, it saves just as intended. But when I run the whole for loop, it does not. Any suggestions?
The surf plot is a part of a one big for loop, so I post just the code that applies to surf plots. In this part 3 different surf plots are ought to be plotted and there is one more just like these 3 couple dozens lines earlier.
%% Plotting error surface plot
% In this section the distance between the points is plotted
figure('units','normalized','outerposition',[0 0 1 1]);
surfPlot = surf(X_grid,Y_grid,delta_x,'FaceAlpha',0.9);
colorbar
zlim([4.5 5.5])
title('Vzdialenosti medzi bodmi v x smere')
xlabel('Šírka snímky')
ylabel('Výška snímky')
zlabel('\Delta x medzi bodmi')
surfPlot.EdgeColor = 'none';
outputBaseFileName = sprintf('Frame %d.jpg',i);
outputSaveFile_sumX = fullfile('C:\Users\Adam\Documents\Škola\Uniza\Diplomová práca\8. Finálne meranie auta\Zabery\calibration images 50mm\Kalibracia 50mm side to side\Results\delta_x',outputBaseFileName);
saveas(gcf,outputSaveFile_sumX)
close all
figure('units','normalized','outerposition',[0 0 1 1]);
surfPlot = surf(X_grid,Y_grid,delta_y,'FaceAlpha',0.9);
colorbar
zlim([4.5 5.5])
title('Vzdialenosti medzi bodmi v y smere')
xlabel('Šírka snímky')
ylabel('Výška snímky')
zlabel('\Delta y medzi bodmi')
surfPlot.EdgeColor = 'none';
outputBaseFileName = sprintf('Frame %d.jpg',i);
outputSaveFile_sumY = fullfile('C:\Users\Adam\Documents\Škola\Uniza\Diplomová práca\8. Finálne meranie auta\Zabery\calibration images 50mm\Kalibracia 50mm side to side\Results\delta_y',outputBaseFileName);
saveas(gcf,outputSaveFile_sumY)
close all
figure('units','normalized','outerposition',[0 0 1 1]);
surfPlot = surf(X_grid,Y_grid,delta_sum,'FaceAlpha',0.9);
colorbar
zlim([6.5 7.5])
title('Absolutne vzdialenosti medzi bodmi')
xlabel('Šírka snímky')
ylabel('Výška snímky')
zlabel('\Delta sum medzi bodmi')
surfPlot.EdgeColor = 'none';
outputBaseFileName = sprintf('Frame %d.jpg',i);
outputSaveFile_sum = fullfile('C:\Users\Adam\Documents\Škola\Uniza\Diplomová práca\8. Finálne meranie auta\Zabery\calibration images 50mm\Kalibracia 50mm side to side\Results\delta_sum',outputBaseFileName);
saveas(gcf,outputSaveFile_sum)
close all
5 Comments
Answers (1)
Veronica Taurino
on 25 Feb 2021
Edited: Veronica Taurino
on 25 Feb 2021
Something like this within each loop?
FolderName='path to save your figures here'
FigList = findobj('Type', 'figure');
for iFig = 1:length(FigList)
FigHandle = FigList(iFig);
FigName = get(FigHandle, 'Name');
saveas(FigHandle, fullfile(FolderName, [FigName '.jpg']));
end
0 Comments
See Also
Categories
Find more on Printing and Saving in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!