I want to write a Matlab function with 'h' and 'V' as vectors to determine the fluid volume of a tank, but I have a problem with the function. The error is in the body of the question. Can someone help me?
Show older comments
function V = hstank2(h,r,hcl) r=0.40; hcl=1.2; Nh = 41; h=linspace(0,(2*r+hcl),Nh); V = zeros(size(h)); i= (h>=0)&&(h<=r); V(i)=(pi/3).*(r.^2*(3.*h(i)-r)-(h(i)-r).^3); i= (h>=r)&&(h<=r+hcl); V(i)=((2/3)*pi*r.^3)+(pi*r.^2.*(h(i)-r)); i= (h>=r+hcl)&&(h<=2*r+hcl); V(i)=((2/3)*pi*r.^3)+(pi*r.^2*hcl)+((pi/3)*... (3*r.^2.*(h(i)-r-hcl)-(h(i)-r-hcl).^3)); end
OUTPUT: Operands to the and && operators must be convertible to logical scalar values.
Error in hstank2 (line 5) i= (h>=0)&&(h<=r); V(i)=(pi/3).*(r.^2*(3.*h(i)-r)-(h(i)-r).^3);
Answers (1)
Roger Wohlwend
on 9 Oct 2014
Try & instead of &&.
i= (h>=0) & (h<=r);
Categories
Find more on Aerospace Blockset in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!