如何在Matlab中修复嵌套函数?

时间:2019-05-12 11:11:25

标签: matlab

% calculate the area of the circle
function a_circle = area(r)
a_circle=pi*r^2;
end

%calculate the volume of the cone
function v = vol(r,h)
v=0.333*area(r)*h;
end

在上面的代码中,表明 vol(r,h)未使用。如何解决此错误?

1 个答案:

答案 0 :(得分:1)

area(r)内定义vol(r, h)

%calculate the volume of the cone
function v = vol(r,h)
   % calculate the area of the circle
    function a_circle = area(r)
       a_circle=pi*r^2;
    end

    v=0.333*area(r)*h;
end