How do I include my simulink model in a live script

I have created a live script that calls a simulink model. The live script calls the simulink model just fine and it runs well, but I want to include the simulink model inside the live script. Is this possible? Thanks and have a great day!

3 件のコメント

Prashant Arora
Prashant Arora 2017 年 10 月 16 日
Hi Christopher, Can you please explain what you mean by "including the Simulink model inside live script"?
If I assume that you would like to save the simulink model and the live script as one "packed" file, I don't believe that's possible.
Hope this helps!
Christopher Smith
Christopher Smith 2017 年 10 月 17 日
Sorry for not being clear enough in the original question. I was hoping for a solution that was similar to the figures in a live script. When using the plot command the live script shows the results of the plot to the right, or in-line. I was hoping that the sim command (or some other command) would pull a screen-shot of the top-level simulink diagram and show it to the right, or in-line.
Sean de Wolski
Sean de Wolski 2017 年 10 月 17 日
See edit

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

 採用された回答

Sean de Wolski
Sean de Wolski 2017 年 10 月 16 日
編集済み: Sean de Wolski 2017 年 10 月 17 日

2 投票

New
I went ahead and wrote a simple function that does this for you. It requires Simulink Report Generator and R2017b. I put in an enhancement request to make this easier as well.
function snapshotModel(model)
open_system(model)
import slreportgen.report.*
r = Report(tempname, 'html');
D = Diagram(model);
D.SnapshotFormat = 'png';
add(r, D);
imshow(imread(char(D.Snapshot.Image)));
close(r);
delete(r.OutputPath);
end
From the live script, call:
snapshotModel('vdp')
Original
I assume you'd like to automatically include a snapshot of the block diagram like you would do with the Simulink Report Generator right?
Since that can generate the image it should be possible to grab that image and imshow it. There may be a more elegant way though.

3 件のコメント

Christopher Smith
Christopher Smith 2017 年 10 月 19 日
Thanks! I will try it when I upgrade to R2017b.
Brian Kempa
Brian Kempa 2021 年 4 月 3 日
This thew an error under R2020b with the cast of D.Snapshot.Image to char. I fixed it by rewritting the imshow line as:
imshow(imread(D.Snapshot.Image.Content.Path));
Xingze Dai
Xingze Dai 2022 年 2 月 10 日
I really appreciate your codes. They are handy and helpful for many times in my homework. Have you considered creating a separate function and publishing it to the Community? I believe it can help many others like me a lot.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgrammatic Model Editing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by