MATLAB: Does Simulink throw an error about variable size matrix from the MATLAB Function block

functionMATLABsimulinksize;variable

Why do I received the following error in Simulink?
Data 'x' is inferred as a variable size matrix, while its properties in the Model Explorer specify its size as inherited or fixed. Please check the 'Variable Size' check box and specify the upper bounds in the size field.
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:MATLAB Function | Category:Coder errorOpen
Simulink cannot determine sizes and/or types of the outputs for block 'MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:Simulink | Category:Model error
Error occurred in 'example/MATLAB Function'.
Component:Simulink | Category:Model error
My MATLAB function only has these few lines of code:
function [x] = fun(A)
y = max(A);
x = find(A==y,1);

Best Answer

This error occurs because the "find" function always returns a variable-length vector.
If you do not want to change the properties of the variable "x" in MATLAB Function to be variable sized as suggested in the error message, you can change the MATLAB Function to not use "find".
For example,
function [x] = fun(A)
[y, x] = max(A);