Create Variable in Simulink block that contains 63 elements.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have 63 Sine blocks that will have different amplitude values. The values will be set from Matlab workspace. I would like to loop through the data and set the amplitudes values programmatically. However, I only know how to create a constant from the Create Variable option in the Simulink Sine block. How to I create a variable that has 63 elements so I can loop throught my data and assign the data correctly?
0 Commenti
Risposta accettata
Paul
il 19 Lug 2024
Hi David,
Question is a bit unclear.
As shown, it appears the model has 63 separate Sine Wave blocks.
That means each time the simulation executes the Amplitude block parameter for each Sine Wave block needs to be assigned, and the plan is to assign those 63 values from the base workspace.
Then, we have "I would like to loop through the data and set the amplitudes values programmatically. ... How to I create a variable that has 63 elements so I can loop throught my data and assign the data correctly?"
What data are you referring to? Does that data determine the values of each of the 63 amplitude parameters?
In any case, what you can do is define a 63 element array in the base workspace, call it CphaseCurrents. Each element of CphaseCurrents defines the amplitude for the corresponding Sine Wave block. For example
CphaseCurrents = ones(1,63);
Then, the Amplitude parameter in each of the 63 Sine Wave blocks would be CPhaseCurrents(1), CphaseCurrents(2), etc, for the fundamental, second harmonic, etc.
Then when you run the simulation it will use the values in the CPhaseCurrents array from the base workspace.
That's certainly the simplest approach. Check the Simulink doc for "parameter sweep" for alternatives as this is a common use case.
Also, you could use one Sine Wave block and set the Amplitude to CPhaseCurrents and set the other block parameters to 63 element vectors as well. In this case the block will output a 63 element vector of all 63 sine waves, which might be easier to process downstream as opposed to having 63 scalar signals. I guess that depends on what you're doing with all of those sine waves.
2 Commenti
Paul
il 20 Lug 2024
Yes, you an set all of the block parameters of the Sine Wave block as indexed elements of a 63-element array, just lik you've done for the Amplitude. Good luck with your project.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Sources in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!