Thursday, October 10, 2013

Export Simulink Data to Matlab

In order to process the data on simulink models in Matlab enviroment, there is an easy way that convert Simulink signals into Matlab variables.

In order to explain it, let's take an example from 'Hysteresis Comparator with Simscape Library' post.

Example: Hysteresis Comparator with Simscape Library


The first think we should do is to convert the signals of interest into 'Test points'. This could be done by right-clicking the signal wire, and click 'Properties'. Also, in order to export the signal data, the 'Log Signal Data' option has to be enable too.
Signal Properties window
We also can give a name to the signal (It is recommended).
Now, the schematic should look like that:
Schematic with test points
If we zoom in the signal wire the test points are clearly seen.:
Zoom in of signal wires

Finally, the next sequeance of instructions will help us to get our signals in Matlab enviroment:

%Different models we have open in Simulink
>>gcs

%Simulate the model
>>sim(gcs): simula los modelos.
%Get the signal output
>>MyOutput=get(logsout,’SignalName’)
>>MyOutput.Values
%plot signal values
>>plot(MyOutput.Values.Time,MyOutput.Values.Data)

In our example:
>> MyOutput=get(logsout,'voltage1');
>> MyOutput2=get(logsout,'voltage2');
>> plot(MyOutput.Values.Time,MyOutput.Values.Data,MyOutput2.Values.Time,MyOutput2.Values.Data)
With all that we get:
Matlab plot
Comparing to the Simulink plot:
Simulink plot

Now, we have the Simulink model data into a Matlab variable and we can use all the Matlab functions to process this data.


Licencia Creative Commons

No comments :

Post a Comment