Using a loop to export UIAxes

7 visualizaciones (últimos 30 días)
Jonathan Moorman
Jonathan Moorman el 12 de Jul. de 2021
Editada: Nikhil Sapre el 13 de Jul. de 2021
Hi all,
I am using app designer and am trying to use a loop to export 5 figures. Below is the code I am using.
for i = 1:5
CurrentAxes = append('app.UIAxes',num2str(i));
exportgraphics(CurrentAxes,append('TestName',num2str(i),'.jpg'))
end
I get the error "Error using exportgraphics. First parameter must specify the axes or chart object."
I suspect that CurrentAxes shouldn't be in string formatt, but I'm not sure what to change it to. Would anyone have an idea?

Respuestas (1)

Nikhil Sapre
Nikhil Sapre el 13 de Jul. de 2021
Editada: Nikhil Sapre el 13 de Jul. de 2021
CurrentAxes in your code is a string. The first argument to exportgraphics should be a figure or axes handle.
Try this code
fig = uifigure;
a = axes(fig);
for i = 1:5
bar(a,magic(randi(5)));
CurrentAxes = append('app.UIAxes',num2str(i));
exportgraphics(fig, [CurrentAxes '.jpg']);
end
Repalce 'fig' in code above, with your app.UIAxes handle and you should get the desired result.
Also, you can use the [ ] to append multiple strings, don't need to use the append() function

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by