i have this error in my code how i can fixed it
1 次查看(过去 30 天)
显示 更早的评论
function I = simpsons(r,v)
↑
Error: Function definition not supported in this context. Create functions in code file.
>> clear;clc ;
r = [0 2.5 5 7.5 10 12.5 15 17.5 20];
v = [0.914 0.89 0.847 0.795 0.719 0.543 0.427 0.204 0];
function I = simpsons(r,v)
v = 2*pi*r.*v;
n = length(v);
i=1;
I=0;
while i<=n-2
I += (r(i+2)-r(i))/6*(v(i)+4*v(i+1)+v(i+2));
i += 3;
end
if (n-i)==1
I += r(i+1)*v(i+1)
end
if (n-i)==2
I += (r(i+2)-r(i+1))/2*(v(i+1)+v(i+2))
end
end
0 个评论
回答(1 个)
Jan
2022-12-19
The error message is exhaustive already: "Function definition not supported in this context. Create functions in code file."
You can create functions inside m-files only, either at the bottom of scripts or in functions. Creating functions in the command window is not possible.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!