How to save the figures after running the batch of testcases in matlab?

5 ビュー (過去 30 日間)
jenny
jenny 2023 年 7 月 11 日
コメント済み: Aniketh 2023 年 7 月 12 日
Hello
I'm running the batch of testcases using a script. These testcases are for running the simulation in model . Each testcase generates the output in the form of scope . How to convert the scope into figure(not screenshot) of each testcase and save it into a folder automatically for say 20 testcases?
Thank you in advance!

回答 (1 件)

Aniketh
Aniketh 2023 年 7 月 11 日
Hi, to automatically convert the scopes into figures and save them in a folder for multiple test cases, you can follow these steps:
  1. Create a folder to store the figures. Let's say you name it "Figures".
  2. Assuming you have a loop or some mechanism to iterate through the test cases, you could programatically convert the output of a scope to jpeg:
print('-sModelName','-djpeg','model.jpeg')
For better customizability you would need to use handles to within the loop to accomodate for multiple cases. An template code for this would look like:
fig = figure;
copyobj(scopeHandle, fig);
filename = sprintf('Figure_%d.png', testCaseNumber); % Customize the filename as per your preference
saveas(fig, fullfile('Figures', filename));
close(fig);
Hope this helped!
  2 件のコメント
jenny
jenny 2023 年 7 月 12 日
編集済み: jenny 2023 年 7 月 12 日
Helllo. Thank you for taking time to answer
When I tried to use the above template,
Im seeing the below error
Unrecognized function or variable 'scopeHandle'.
Aniketh
Aniketh 2023 年 7 月 12 日
Hi, sorry for the confusion that was just a sample code, I had attached the link to the handle doc page to refer and create a handle for the images.
Anyway here a few resources for the same:

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTesting Frameworks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by