How can I save outputs in a matrix?

2 views (last 30 days)
JongYun Kim
JongYun Kim on 15 Sep 2015
Answered: Walter Roberson on 15 Sep 2015
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

Answers (1)

Walter Roberson
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

Categories

Find more on Data Types 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!