Using a loop to export UIAxes

6 Ansichten (letzte 30 Tage)
Jonathan Moorman
Jonathan Moorman am 12 Jul. 2021
Bearbeitet: Nikhil Sapre am 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?

Antworten (1)

Nikhil Sapre
Nikhil Sapre am 13 Jul. 2021
Bearbeitet: Nikhil Sapre am 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

Kategorien

Mehr zu Printing and Saving finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by