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

1 回表示 (過去 30 日間)
jenny
jenny 2024 年 5 月 13 日
回答済み: Poorna 2024 年 5 月 15 日
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!! :)

回答 (1 件)

Poorna
Poorna 2024 年 5 月 15 日
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!

カテゴリ

Help Center および File ExchangeScopes and Data Logging についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by