How to use an array as an input block in Simulink?
168 views (last 30 days)
Show older comments
I have a digital 2nd order state variable filter in Simulink (picture attached). The idea is that the input is both filtered and also the derivatives generated - the actual implementation is correct. I want to use a [40000x1] array that has already been generated in Matlab as the input to the filter, and from this the block diagram will process the outputs as shown in the diagram. At the minute I am using a constant block with the variable name of the array (motorcurrent) as the input. I am running the simulation from t =0 to 10s with a step size of 0.001 and 4th order RK integration. The issue is that this results in the output variables (yf,yfdot etc.) being [10001 x 40000] size arrays, when what I really want is the same size as the input. Anyone know where I'm going wrong?
EDIT: I figured it out. If anyone's interested I needed to create a timeseries object in Matlab:
tscale = linspace(0,40,40000) % the step size in the program is 0.001, so 40000 iterations is 40s
ts = timeseries(motorcurrent,tscale)
Then in the Simulink model, I used a 'From workspace' block instead of the constant as the input, with the value being ts.
2 Comments
Fangjun Jiang
on 27 Oct 2020
Edited: Fangjun Jiang
on 27 Oct 2020
To use FromWorkspace block to import data from MATLAB to Simulink, the data needs to be in certain formats. The most common format is array, in which, the first column is time step, the second column is the first signal data, the third column (if any) is the second signal data, etc. Click Help of the Constant block to see document.
Answers (0)
See Also
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!