saving Plots in a loop

9 visualizzazioni (ultimi 30 giorni)
Tamadur AlBaraghtheh
Tamadur AlBaraghtheh il 1 Ago 2018
Commentato: OCDER il 2 Ago 2018
Hi Am trying to plot a 132 files .. the problem when I use contour plot I got the error "Error using saveas (line 58) Invalid handle." Where this error is not appearing when I use surf / mesh or any other plot? Can you help ?
Path = '........./Trialwithname/Figures';
for i = 1:132
c1 = [D{i}];
a1 = table2array(c1);
c2 = reshape(a1,99,99);
hplot = surf(x,y,c2);
saveas(hplot,fullfile(Path, sprintf('fig%02d.jpg', i)));
end

Risposta accettata

OCDER
OCDER il 1 Ago 2018
The outputs to contour is different from axes handles given by surf. You have to find the figure handle and feed that to the saveas function. Example:
Path = '........./Trialwithname/Figures';
for i = 1:132
c1 = [D{i}];
a1 = table2array(c1);
c2 = reshape(a1,99,99);
if i == 1
[~, hc] = contour(x, y, c2);
haxes = get(hc, 'parent');
hplot = get(haxes, 'parent');
else
contour(haxes, x, y, c2);
end
%hplot = surf(x,y,c2);
saveas(hplot,fullfile(Path, sprintf('fig%02d.jpg', i)));
end
  2 Commenti
Tamadur AlBaraghtheh
Tamadur AlBaraghtheh il 2 Ago 2018
Thank you :)
OCDER
OCDER il 2 Ago 2018
You're welcome!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by