MATLAB: Problem using Embedded MATLAB Fcn Block in Simulink

embedded matlab functionfrom workspaceinput output mismatch

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.

Best 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.
Related Question