Error Message: Output argument "I" (and maybe others) not assigned during call to "simpsons".

1 次查看(过去 30 天)
Hi, so I recently wrote a function
function I = simpsons(f,M,a,b)
h = (b-a)/(M-1);
f = @(x) x;
if rem(M,2) == 0
simpsons1(f,M,a,b)
elseif rem(M,3) == 0
simpsons2(f,M,a,b)
else
simpsons2(f,4,a,3*h) + simpsons1(f,M-3,3*h,b)
end
However, when I call the function in another script, I get the message Output argument "I" (and maybe others) not assigned during call to "simpsons".
This is my script
%i calculating pressure at a given depth
p0 = 101325;
g = 9.81;
for i = 1:1:43
I = 1;
I = simpsons(1,43,0,z(i));
pz = I;
pzm(i) = p0 + I*g;
end

回答(1 个)

Stephen23
Stephen23 2020-8-11
编辑:Stephen23 2020-8-11
Although you specified one output argument I:, nowhere in the code did you define I:
function I = simpsons(f,M,a,b)
...
I = ???? % you did not define I anywhere
Most likely you will want to return the simpsons2 ouputs:
function I = simpsons(f,M,a,b)
h = (b-a)/(M-1);
%f = @(x) x;
if rem(M,2) == 0
I = simpsons1(f,M,a,b);
elseif rem(M,3) == 0
I = simpsons2(f,M,a,b);
else
I = simpsons2(f,4,a,3*h) + simpsons1(f,M-3,3*h,b);
end

类别

Help CenterFile Exchange 中查找有关 Downloads 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by