How do I place each answer under a one column matrix?

r = [1, 2.5, 3.25, 4.3, 7.6];
h = [12.3, 14.1, 17.6];
j =15;
for i = 1:length(r);
for k = 1:length(h);
vol = (1/3)*pi*r(i)*h(k)
end
end

 Accepted Answer

r = [1, 2.5, 3.25, 4.3, 7.6];
h = [12.3, 14.1, 17.6];
j =1;
vol=zeros(15,1); % preallocate
for i = 1:length(r);
for k = 1:length(h);
vol(j,1) = (1/3)*pi*r(i)*h(k);
j=j+1;
end
end
Gives:
vol =
12.8805
14.7655
18.4307
32.2013
36.9137
46.0767
41.8617
47.9878
59.8997
55.3863
63.4916
79.2519
97.8920
112.2177
140.0731

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!