Using a loop to export UIAxes

7 views (last 30 days)
Jonathan Moorman
Jonathan Moorman on 12 Jul 2021
Edited: Nikhil Sapre on 13 Jul 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?

Answers (1)

Nikhil Sapre
Nikhil Sapre on 13 Jul 2021
Edited: Nikhil Sapre on 13 Jul 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

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!