Problem using Embedded MATLAB Fcn Block in Simulink?

Hi,
I have simulated a DAC model using Simulink. I have used a 'To Workspace' block at the output which gives me a structure 'DAC_OUT' at the workspace out of which I need two column vectors 'DAC_OUT.time' and 'DAC_OUT.signals.values' as explained later. Now, I have created another Simulink model to evaluate the FFT of a signal, in which I have used 'From Workspace' block to pick up the signal and time values from the workspace (i have written [DAC_OUT.time DAC_OUT.signals.values] in the data field entry of 'From Workspace' block). I have also used an Embedded MATLAB Function block, in which I have embedded a code (an m-file function) to evaluate the FFT of the input signal. However, there are two input arguments of this function (input,time) which means the Embedded MATLAB Func. block will have two input ports (input and time). However, the 'From Workspace' block has only one output port containing both time stamps and signal values corresponding to them (I guess). Now, how do i connect this single output port of 'From Workspace' to two input ports for my Embedded MATLAB function?
Thanks and regards.

 Accepted Answer

Provided that the From Workspace block is producing a 1x2 signal of the form [time value], you can use the Demux block to separate the two signals (Alternatively, you can use the Selector block). However, I'm not so sure that the From Workspace block in this case will also output the time samples - I would have guessed that it outputs only DAC_OUT.signals.values according to the time samples in DAC_OUT.time. If you find that the time is not being output, you can set the Data field to [DAC_OUT.time DAC_OUT.time DAC_OUT.signals.values] instead.

More Answers (1)

When you use the "From Workspace" block, you can directly type in DAC_OUT because it is saved by the "To Workspace" block in the format of "structure with time".
When Simulink runs simulation, it has its own clock. The time stamp within the "From Workspace" signal is to make sure the signal value aligns with the Simulink clock. If you need the clock information somewhere else like you do in the Embedded MATLAB function, you can just use the clock block from the Sources library.

Community Treasure Hunt

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

Start Hunting!