How do I use Simulink-PS Converter with a data vector importet from Matlab workspace?

12 次查看(过去 30 天)
I would like to perform a part of my Matlab simulation in Simulink. Therefore, I am using the From Workspace and To Workspace blocks to share the data. By using the Simulink-PS Converter block right after the From Workspace block, as shown ins this simnplified schematic
only constant values can be used. Example using a constant Value 1:
WSDataIn = [0 1];
a = sim('PS_Test','SimulationMode','normal');
Example Using a vector [1 1]:
WSDataIn = [0 1 1];
a = sim('PS_Test','SimulationMode','normal');
The following error massage appears:
Error due to multiple causes.
Caused by:
Error in port widths or dimensions. Output port 1 of 'PS_Test/From Workspace' is a one
dimensional vector with 2 elements. Error in port widths or dimensions. Input port 1 of
'PS_Test/Simulink-PS Converter' is a one dimensional vector with 1 elements.
A sine wave block in simulink is also time-variant and works with the converter. How can I use Simulink-PS Converter with a data vector importet from Matlab workspace? Because I would linke to use a precalculated signal as a signal source.

采纳的回答

Birdman
Birdman 2017-10-23
编辑:Birdman 2017-10-23
Try this model instead. In your model, the from workspace block provides constant data throughout the simulation which is 1x1 scalar value. If you make the input data nx1, you need all your block to accept nx1 vector but it is not possible. However, I edited your model where you can define different inputs depending on the length of the simulation time. I used a MATLAB Function. See this model and I hope it helps.
Do not forget, if your signal is precalculated, it has to be the same length with the simulation time!

更多回答(1 个)

Gordon
Gordon 2017-10-23
Thanks for the quick reply!
I used your file as a starting point and adjusted it to be able to use any signal precalculated in MATLAB.
My solution is attached. The following matlab example can be used to perform a simulation. A random signal is used as an example.
dataIn = randn(1,1000);
WSDataIn = [0 dataIn];
set_param('PS_Test', 'StopTime', num2str(length(WSDataIn)-2))
a = sim('PS_Test','SimulationMode','normal');
dataOut = a.WSDataOut.Data;
plot(dataIn)
hold all
plot(dataOut)
  1 个评论
Birdman
Birdman 2017-10-23
Perfect. If my answer satisfied you, you can accept the answer so that other people having the same problem will know that there is a valid solution.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by