i have this error in my code how i can fixed it
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Jan
am 19 Dez. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!