How can I save outputs in a matrix?
4 views (last 30 days)
Show older comments
r = 0.6 ;
a = @(h) ((pi .* h) .* (3 .* r.^2 - h.^2)) ./ 3 ;
b = @(h) pi .* 0.6^2 .* (h-0.6) ;
c = @(h) pi.*(1/3).*(r.^2 + r.*(3/4).*(0.8-(h-2)) + ((3/4) .* (0.8-(h-2)).^2)) .* (h-2) ;
V = [];
A = a(0.6) ;
B = b(2) ;
h = 0 : 0.1 : 2.8 ;
for i = 0:0.1:2.8;
if h<=0.6
V=a(i)
elseif 0.6<h<=2
V=A + b(i)
else 2.0<h<=2.8
V=A+B+c(i)
end
end
I wanna make a matrix of V
0 Comments
Answers (1)
Walter Roberson
on 15 Sep 2015
hvals = 0:0.1:2.8;
for hidx = 1 : length(hvals);
h = hvals(iidx);
if h<=0.6
V(hidx) = a(h);
elseif 0.6<h & h<=2
V(hidx) = A + b(h);
else
V(hidx) = A + B + c(h);
end
end
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!