Using a loop to export UIAxes

9 次查看(过去 30 天)
Jonathan Moorman
Jonathan Moorman 2021-7-12
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?

回答(1 个)

Nikhil Sapre
Nikhil Sapre 2021-7-13
编辑:Nikhil Sapre 2021-7-13
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

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by