Azzera filtri
Azzera filtri

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

12 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Birdman
Birdman il 23 Ott 2017
Modificato: Birdman il 23 Ott 2017
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!

Più risposte (1)

Gordon
Gordon il 23 Ott 2017
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 Commento
Birdman
Birdman il 23 Ott 2017
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.

Accedi per commentare.

Categorie

Scopri di più su Modeling 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!

Translated by