Unrecognized function or variable 'tankvolume'.

I keep receiving unrecognized function or variable 'tankvolume' when I call the function having R=0.9 and d=1 as arguments.
here is my code.
function Vol = tankvolume(R, d)
if d < R
Vol = pi * d ^ 3 / 3;
elseif d <= 3 * R
V1 = pi * R ^ 3 / 3;
V2 = pi * R ^ 2 * (d - R);
Vol = V1 + V2;
else
Vol = 'overtop';
end

1 个评论

I have saved the function on my pc and run it, there's no problem.
There could be several reasons why you're getting that error.
Maybe the function is not saved in the "current folder", or you might have mispelled the function name when calling it.

请先登录,再进行评论。

 采纳的回答

It looks like either you are running the function using F5 key or run button. You need to save the function on the name tankvolume and keep in the present working directory, define your inpus and then call the function.
Or copy the below code into a script and run it.
R=0.9; d=1
d = 1
v = tankvolume(R,d)
v = 1.0179
function Vol = tankvolume(R, d)
if d < R
Vol = pi * d ^ 3 / 3;
elseif d <= 3 * R
V1 = pi * R ^ 3 / 3;
V2 = pi * R ^ 2 * (d - R);
Vol = V1 + V2;
else
Vol = 'overtop';
end
end

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by