Create Variable in Simulink block that contains 63 elements.

2 visualizaciones (últimos 30 días)
David Cole
David Cole el 19 de Jul. de 2024
Comentada: Paul el 20 de Jul. de 2024
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?

Respuesta aceptada

Paul
Paul el 19 de Jul. de 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 comentarios
David Cole
David Cole el 20 de Jul. de 2024
I was able to utilize the approach of 63 sine blocks and use the CphaseCurrents(1), CphaseCurrents(2), ... CphaseCurrents(63) to set the amplitude value of each block. I am using the 63 sine blocks as in control signal for a control current source block. Since I have a three phase system ,this approach took a long time to program and I had to be very careful not to make a mistake.
Currently, I also manually set the freqency parameter of the block. I would also need to set an array of the frequency. I will see if I can set the frequency value as a parameter as an array as well.
Thanks for the answer.
Paul
Paul el 20 de Jul. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by