Integral in Simulink fcn Block
3 次查看(过去 30 天)
显示 更早的评论
Hey,
frist: I'm pretty new to Matlab / Simulink. I'm wrote an algorithm to generate a trajectory in Matlab and wanted to integrate my working Matlab code into a Simulink Project by using a Fcn Block.
Within my algorithm I have to integrate a cos / sin function. My code looks like:
ds = .1;
length = 1;
phi = 0;
R=5.5;
A=sqrt(R*length);
i=1;
int_x1=@(l) cos((l.^2/(2*A.^2)) + phi);
int_y1=@(l) sin((l.^2/(2*A.^2)) + phi);
x=zeros(1,(length / ds)+1);
y=zeros(1,(length / ds)+1);
for l=0:ds:length
x(i)=integral(int_x1,0,l);
y(i)=integral(int_y1,0,l);
i=i+1;
end
This generates x and y coords in ds steps. It builds a Clothoid for a Radius of 5.5 within a length of 1.
My Problem with Simulink is, that the integral function does not work.
"Function 'integral' not supported for code generation."
In the next step I tried to fix this by the use of:
coder.extrinsic('integral');
which leads to:
"An error occurred while running the simulation and the simulation was terminated
Caused by:
- First input argument must be a function handle. "
Is there any possibility to numerical solving of integrals within a function block?
2 个评论
Jim Riggs
2022-11-10
I'm not sure what you are trying to do in Simulink. Can you post an image of your Simulink model, and specify exactly what code is in the Fcn block?
回答(1 个)
Fangjun Jiang
2022-11-10
You need to understand the difference between MATLAB and Simulink.
This Simulink block diagram will give you the curve. Set the values of "A" and "phi" in base workspace.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!