saveas won't save my figure when in a for cycle
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Veronica Taurino
2021-2-25
编辑:Veronica Taurino
2021-2-25
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!