필터 지우기
필터 지우기

Trying to create a matrix by nesting a for loop in another for loop

조회 수: 2 (최근 30일)
Michael Costa
Michael Costa 2020년 10월 31일
댓글: Michael Costa 2020년 11월 1일
I am trying to create a nx9 matrix by nesting a for loop in another for loop, where n is the number of iterations of the first for loop, and 9 is the number of iterations in the nested for loop. Specifically, I am iterating through different values for the NTU of a heat exchanger in the first loop, and the nested loop iterates through 9 different surface areas (A) from actual heat exchangers. The overall heat transfer coefficient is calculated for each heat exchanger for each different NTU. Here is what I have so far
i = 0;
for NTU = 2.5:0.1:3.5
i = i + 1;
eff(i) = effectiveness(NTU, c, 'One Shell Pass');
Q(i) = eff(i)*Qmax; %kW
T5(i) = Q(i)/Cmin + T4;
T14(i) = T13 - Q(i)/Cmax;
NTU_i(i) = NTU;
%Finding the overall transfer coefficient
for j = 1:9
U(j) = ((NTU*Cmin)/A(j));
end
end

채택된 답변

Sindar
Sindar 2020년 11월 1일
편집: Sindar 2020년 11월 1일
No need for loops, except if effectiveness doesn't accept arrays
% nx1
NTU = (2.5:0.1:3.5).';
for i=1:length(NTU)
eff(i) = effectiveness(NTU(i), c, 'One Shell Pass');
end
Q = eff*Qmax; %kW
T5 = Q./Cmin + T4;
T14 = T13 - Q./Cmax;
% make sure A is the right shape
if isequal(size(A),[1 9])
elseif isequal(size(A),[9 1])
A = A.';
else
error('A is not the expected size: 1x9')
end
%Finding the overall transfer coefficient
% elementwise division will expand nx1 NTU / 1x9 A into nx9 U
U = (NTU.*Cmin)./A;
  댓글 수: 1
Michael Costa
Michael Costa 2020년 11월 1일
Effectiveness will take an array. This worked great. Thanks for the help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by