Using set_param for multiple variables.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Don Brohaugh
le 3 Nov 2015
Modifié(e) : Sebastian Castro
le 4 Nov 2015
I am trying to update 20 variables in a Simulink model by using set_param in an m script file. Is there any way to do this using a "for i=1:20" subroutine referencing Constant1, Constant2, Constant3, etc, as Constant(i) and with data from Q(i), so I do not have to write 20 separate entries in the set_param command?
0 commentaires
Réponse acceptée
Sebastian Castro
le 4 Nov 2015
Modifié(e) : Sebastian Castro
le 4 Nov 2015
Sure. sprintf is handy here.
for idx = 1:20
blockName = sprintf('myModel/Constant%i',idx);
blockValue = sprintf('Q(%i)',idx);
set_param(blockName,'Value',blockValue);
end
You can also use the num2str function if that works better.
set_param(blockName,'Value',num2str(Q(idx));
- Sebastian
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Model, Block, and Port Callbacks 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!