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
0 件のコメント
回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で 3-D Volumetric Image Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!