Hey Amjad,
The issue in your model is that the custom code written inside the MATLAB function block, is not supported for code-generation. This is because you're using structures inside the MATLAB Function block, and structs have limited capability while being used inside code generatable functions (you can read more about it here and here).
Thus when you use variable sized 'fname' inside your MATLAB Function block, which in turn calls 'load' and assigns the 'load' output to another struct named 'x', MATLAB throws an error because 'fname' is a 'non-constant expression'.
A workaround could be to use Dynamic Mask Callbacks and add a callback to the 'fileName' parameter, so that whenever the user modifies the 'fileName' param, the callback is called.
You can then add the custom code in the callback.
e.g. for the attached model, you could write this code in the callback
fileName = get_param(gcb,'File_to_Load');
x = load(fileName);
set_param(gcb, 'f', num2str(x.factor));
Wherein 'f' is another parameter in the subsystem mask which you can then pass to your MATLAB Function block.
I have attached the modified Simulink model for your reference.
You can refer to the following link to learn more about callbacks:
Hope this helps!