I want to solve ODEs in Simulink by using MATLAB Function Block, but i couldn't write all code directly in the MATLAB FunctionBlock, cause 'ode23s' not supported for code generation. So i try to use coder.extrinsic and to call a function from another m-file. Below is a simple example.
But i don't know how to pass the mu value from Simulink to the standard function. How can i realize it or should i just write functions in Block and m-file in different ways?
My Simulink Mode:
and the MATLAB Function Block:
1. function y = func(mu)
5. y = 0;
6. y = standard();
the standard function (that from other m-file) should be called in MATLAB Function Block:
1. function y = standard(mu)
3. odefcn = @(t,y) [y(2); mu*(1-y(2)^2)*y(2)-y(1)];
4. [t,Y] = ode45(odefcn, [0 20], [2; 0]);
6. y = Y(:,1);
But i always get the error:
An error occurred while running the simulation and the simulation was terminated
I have also already tried assignin( to save the value in workspace), and save (in a mat) in Block, also not supported for code generation. Thank you guys in advance:)