Create Variable in Simulink block that contains 63 elements.
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Paul
2024년 7월 19일
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
Paul
2024년 7월 20일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Sources에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!