Creating a Loop with "SAVEAS" after generating Figures

1 visualización (últimos 30 días)
Leonel Mendes
Leonel Mendes el 23 de Mayo de 2020
Comentada: Walter Roberson el 23 de Mayo de 2020
Hello u all!
I'm trying to use a for-loop to save my already generated pictures into different files, but I can't figure out how to index those figures:
for i = 1 : 10
filepath = fullfile(source,sprintf('%s.png',figname{i,1})); %%figname is a cell with each figure's name
saveas('??',filepath);%%figures going from f1 - f10
end
Is there a way of doing it or do I have to use SAVEAS after generating each fig?
THX

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Mayo de 2020
As you generate each figure, store its handle into a vector of figure handles, such as fighandles(). Then index it in your loop.
for i = 1 : length(fighandles)
filepath = fullfile(source,sprintf('%s.png',figname{i,1})); %%figname is a cell with each figure's name
saveas(fighandles(i), filepath);
end
  2 comentarios
Leonel Mendes
Leonel Mendes el 23 de Mayo de 2020
like:
f1 = figure
%%whatever
fighandle(1) = f1
f2 = figure
%%whatever
fighandle(2) = f2
and so on...?
Walter Roberson
Walter Roberson el 23 de Mayo de 2020
For example,
for i = 1 : 10
fighandles(i) = figure();
axhandles(i) = axes('Parent', fighandles(i));
end
plot(axhandles(7), 1:10, rand(1,10))
hold(axhandles(7), 'on')
bar(axhandles(7), 1:10, randi(9, 1, 10));
hold(axhandles(7), 'off')
title(axhandles(7), figname{i});

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Printing and Saving en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by