The sim function cannot be directly used inside a Simulink Matlab Function block because it is a top-level command for running Simulink simulations.
Instead, you can use the Simulink API functions within the Matlab Function block which will provide the same functionality as you're expecting.
You just need to replace the sim('calc') command with the necessary Simulink API functions to simulate your C-Caller block.
To do this, you need to add a MATLAB function block to your Simulink model. For that, open the Matlab Function block and write your main function code inside it. Make sure to specify the appropriate inputs and outputs for the block.
Use the following code for the same.
function out = myFunction(in)
% Define the simulation parameters
tStart = 0;
tEnd = 10;
% Load the Simulink model
load_system('calc');
% Set the input values
set_param('calc/InputBlock', 'Value', num2str(in)); % Replace 'calc/InputBlock' with the path to your input block
% Simulate the model
simOut = sim('calc', 'StartTime', num2str(tStart), 'StopTime', num2str(tEnd));
% Extract the output value
out = simOut.OutputBlock(end); % Replace 'OutputBlock' with the path to your output block
end
Here in is the input value passed to the Matlab Function block. and out is the output value returned by the Matlab Function block.
After implementing the code inside the Matlab Function block, you can connect the block to the rest of your Simulink model as needed.