필터 지우기
필터 지우기

Nested For loop to test two data sets

조회 수: 1 (최근 30일)
Andrew Ghali
Andrew Ghali 2018년 3월 13일
댓글: Abraham Boayue 2018년 3월 13일
I need help running through two sets of data to send to a function. I want to run each value of d for the entire range of Q values and store it in a matrix. This is what I could think of but this only tests a single d value for a single Q value. Please help me.
i=1
for d=1:1:5
for Q=10:1:15
[Re]= Reynold(d,Q);
Reynolds(i,1)= Re;
i=i+1
end
end
  댓글 수: 1
Abraham Boayue
Abraham Boayue 2018년 3월 13일
Oh, I forgot the part that you wanted to feed your function with d and Q, but you can still use the matrix for this purpose. Re =Reynolds(d(i),A(i,:)) This statement will make the function to run i times, one output for each value of d and the corresponding values of Q. Note that A (i, :) is a vector value of Q for every d value.

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

답변 (2개)

Abraham Boayue
Abraham Boayue 2018년 3월 13일
d = 1:5;
Q = 10:15;
N = length(d);
M = length(Q);
v = zeros(1,M);
A = zeros(N,M);
for i = 1:N
for k =1:M
v(k) = Q(k);
A(i,:) = v;
end
end
disp(A)
  댓글 수: 1
Abraham Boayue
Abraham Boayue 2018년 3월 13일
This code would do the trick, each row of the matrix A represents the number of times that d runs and the columns are the values of Q.

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


KSSV
KSSV 2018년 3월 13일
N = 5 ;
D = 1:1:5 ;
Q = 10:1:!5 ;
Re = zeros(length(D),length(Q),N) ;
for i=1:N
R = zeros(length(D),length(Q)) ;
for d=1:length(D)
for q=1:length(Q)
R(D(d),Q(q)= Reynold(D(d),Q(q));
end
end
Re(:,:,i) = R ;
end

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by