How do I include my simulink model in a live script
52 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Christopher Smith
le 14 Oct 2017
Commenté : Xingze Dai
le 10 Fév 2022
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 commentaires
Réponse acceptée
Sean de Wolski
le 16 Oct 2017
Modifié(e) : Sean de Wolski
le 17 Oct 2017
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 commentaires
Brian Kempa
le 3 Avr 2021
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
le 10 Fév 2022
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Simulink Environment Customization dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!