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

 채택된 답변

madhan ravi
madhan ravi 2018년 12월 16일
편집: madhan ravi 2018년 12월 16일
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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2018년 12월 16일

댓글:

2018년 12월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by