Effacer les filtres
Effacer les filtres

How to take the screenshots of two or more scopes of a single testcase while running the simulations?

4 vues (au cours des 30 derniers jours)
Hello,
I'm running the simulations which shows the outputs in scopes. I could able to take the screenshots of the one scope using below commands
shh = get(0,'ShowHiddenHandles'); %finds the open figures
set(0,'ShowHiddenHandles','On');
set(gcf,'PaperPositionMode','auto'); %gcf-current figure handle
set(gcf,'InvertHardcopy','off');
saveas(gcf,sprintf('TC%d.png',j));
set(0,'ShowHiddenHandles',shh);
I could not able to take the screenshot of more than one scope of a single testcase. Here I'm using gcf command. Is there anyother command I have to use?
Any inputs highly appreciated!!
Thank you in advance!! :)

Réponses (1)

Poorna
Poorna le 15 Mai 2024
Hi yogi,
I see you want save the plots from all the scopes in png format. It is to be noted that 'gcf' will point to the current figure handle. Everytime you complete the simulation, 'gcf' will point to one of the figure handles, in your case it will point to one of the scope outputs. In order to export the outputs of all the scopes you need to get the handles of all the figures. "findobj" function can be used to get handles of all graphical objects of type "figure" as shown below:
figs = findobj("Type", "figure");
Now you can iterate over each figure and export it to png as shown below:
for i = 1:length(figs)
set(figs(i),'PaperPositionMode','auto'); %gcf-current figure handle
set(figs(i),'InvertHardcopy','off');
saveas(figs(i),sprintf('TC%d.png',i));
end
To know more about "gcf" and "findobj" refer to the following documentation:
Hope this Helps!

Community Treasure Hunt

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

Start Hunting!

Translated by