MATLAB: Does “pchip” not return all outputs when used in a MATLAB Function Block

MATLABsimulink

I'm working in MATLAB and Simulink to develop an algorithm that uses "pchip" to do some interpolation. To test the interpolation algorithm, I wrote a MATLAB function that does the processing and worked on that until I was satisfied with the results. I then copied this function into a MATLAB Function Block, so that I could make use of the algorithm in Simulink. When trying to run my model, I get syntax errors when trying to access different fields of the "pchip" output struct, saying those fields no longer exist. Why is this happening?

Best Answer

MATLAB Function Blocks generate code for the contents of the block to integrate it into the Simulink Environment. Accordingly, you need to be careful of Code Generation limitations for any function that gets used in a MATLAB Function Block.
For "pchip", when code is generated from the function, a different implementation is used that changes the structure of the outputs. In order to access the original output fields from the code generation implementation, you must make use of the "unmkpp" function, which will extract all of the information from the output of the code generation implementation.
More on "pchip" can be found here:
More on "unmkpp" can be found here: