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