Using set_param for multiple variables.
    9 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Don Brohaugh
 il 3 Nov 2015
  
    
    
    
    
    Modificato: Sebastian Castro
    
 il 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 Commenti
Risposta accettata
  Sebastian Castro
    
 il 4 Nov 2015
        
      Modificato: Sebastian Castro
    
 il 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 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Model, Block, and Port Callbacks in Help Center e File Exchange
			
	Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!