How do I pass a Complex input to a MATLAB file S-function?

I have an MATLAB file S-function and I want it to handle complex inputs.

 Accepted Answer

MATLAB file S-functions cannot handle complex inputs, unlike C-Mex S-functions. However, the following workaround can be used to have MATLAB file S-functions work with complex inputs.
1. Use the Complex to Real-Imaginary block from the Simulink Math library to split the complex signal into two parts.
2. Use a Mux block from the Signals & Systems library to combine these two parts into a two element vector.
3. Pass this vector as input to the MATLAB file S function.
4. Make sure inside the MATLAB file S function the number of inputs is set to 2
sizes.NumInputs = 2;
An example that demonstrates how complex input can be handled is attached at the bottom of the page.
In the example, the conjugate of a complex number is calculated using a MATLAB file S-function.

More Answers (0)

Categories

Find more on Block and Blockset Authoring in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!