saveas won't save my figure when in a for cycle
Afficher commentaires plus anciens
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 commentaires
Cris LaPierre
le 25 Fév 2021
What does it or does it not do when this is placed inside a for loop?
Ignoring the saving part for a minute, does your code even create the figures you want to save when inside a for loop?
Adam Rajcan
le 25 Fév 2021
Modifié(e) : Adam Rajcan
le 25 Fév 2021
Image Analyst
le 25 Fév 2021
Give us the whole for loop. You probably have the for loop setup so that the iteration counter has no loops, maybe something like
for k = 1 : 0
or something that evaluates to 0.
Adam Rajcan
le 25 Fév 2021
Adam Rajcan
le 25 Fév 2021
Modifié(e) : Adam Rajcan
le 25 Fév 2021
Réponses (1)
Veronica Taurino
le 25 Fév 2021
Modifié(e) : Veronica Taurino
le 25 Fév 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
Catégories
En savoir plus sur Subplots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!