How can I evaluate elements in an array individually. Typing in a range of eg -2:2 the negative elements are being evaluated at an incorrect condition (1st elseif condition). What is the problem

1 回表示 (過去 30 日間)
function [volume] = vol(h)
%Function computes the volume of a tank in the shape of a cylinder (h=10) at the bottom and a
%frustrum (h=5) above it
h = input ('Type height range here');
for c = h
if c <= 0 %If h is negative or 0 return zero for volume
volume = h.*0;
elseif (0 < c) && (c <= 10) %If h is the range of the cylinder height compue volume using the formula
volume = 16*pi.*h;
elseif (10 < c) && (c <= 15) %If h is not in range of cylinder height, add max cylinder volume to frustrum volume
volume = 160*pi + (8/3)*pi*(((h./2-1).^3)- 64)./4;
elseif (c > 15) %Otherwise if h is above h max for tank return max volume for tank at h=15
h=(h.*0 + 15);
volume = 160*pi + (8/3)*pi*(((h/2-1).^3)- 64)./4; (2nd els
else
disp('Please type in an acceptable value')
end
end

回答 (1 件)

madhan ravi
madhan ravi 2020 年 9 月 22 日
elseif (c > 0) && (c <= 10)
elseif (c > 10) && (c <= 15)

カテゴリ

Help Center および File Exchange3-D Volumetric Image Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by