Using a loop to export UIAxes

3 visualizzazioni (ultimi 30 giorni)
Jonathan Moorman
Jonathan Moorman il 12 Lug 2021
Modificato: Nikhil Sapre il 13 Lug 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?

Risposte (1)

Nikhil Sapre
Nikhil Sapre il 13 Lug 2021
Modificato: Nikhil Sapre il 13 Lug 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

Categorie

Scopri di più su Printing and Saving in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by