nested Loop with complicated conditions
이전 댓글 표시
Hi every1, i need your help please. i am trying to use nested For-Loop for my problem but i am not sure if my code is correct. I have a vektor of nX128 (n can be any number of rows), i have to calculate a certain value (F) form the first row 1X128(from the first Loop in my code), and use (F) to calculate (Z) and (R) in next loop 2X128. And for the next loop i have to use the previous value of (F) to calculate (Z)and (R) till the end of n. As a result i want the last value of (R), i mean from the last nX128. It is quite complicated so i calculate the values of (F) and (R) with excel to have an idea in which rang of values they have to be. Comparing to the result of excel, the (R)-Value is different and very very larg from this code.
Rp=1; % i have to give a value for the first (R) to beginn the calculation
for j = 1:size(Pulses,1) % the first Loop with vector named Pulses = [1X128]
if j == 1
Z(j,:)= calculateCPW(Pulses(j,:),SBP,DBP,Fs); % Function to calculate (Z)
F(j,:) = CalcRootFlow(Z(j,:),MAD,Pulses(j,:),Rp); % anther fuction to calculate (F) from the first (Z) and
the first Value of (R=Rp=1)
end
for j = 1:size(Pulses,1)% the next Loop
if j >1 % hier should beginn with Pulses=[2X128]
Z(j,:)= calculateCPW(Pulses(j,:),SBP,DBP,Fs); % again the Function to calculate (Z) from [2X128]
M1 = mean(F(j-1,:)); % the mean of the previous value of (F) ( for the 2.Loop shloud be from the 1.Loop and
for upto the 3.Loop the previos Value)
M2 = mean(Z(j,:));% the mean of (Z) in this Loop
R(j,:)=M2/M1; % calculation of (R)
F(j,:) = CalcRootFlow(Z(j,:),MAD,Pulses(j,:),R(j,:)); % again the Function to calculate (F) to use it for
[3X128] and so on....
end
end %End of the next Loop
end %End of the first Loop
R = R(size(NormedPulses,1),:); % hier i want to see all n values of (R)
댓글 수: 3
Ruaa
2018년 7월 30일
Dennis
2018년 7월 30일
I just wanted to write a 1-loop solution, however i realised that you wrote that you use F to calculate R and Z,but i am not sure if you implemented that - atleast the calculation of Z does not use F.
Rp=1; % i have to give a value for the first (R) to beginn the calculation
for j = 1:size(Pulses,1) % the first Loop with vector named Pulses = [1X128]
if j == 1
Z(j,:)= calculateCPW(Pulses(j,:),SBP,DBP,Fs); % Function to calculate (Z)
F(j,:) = CalcRootFlow(Z(j,:),MAD,Pulses(j,:),Rp);
else
Z(j,:)= calculateCPW(Pulses(j,:),SBP,DBP,Fs);
^is this supposed to be F(j-1,:) ?
M1 = mean(F(j-1,:));
M2 = mean(Z(j,:));% the mean of (Z) in this Loop
R(j)=M2/M1; % calculation of (R)
F(j,:) = CalcRootFlow(Z(j,:),MAD,Pulses(j,:),R(j));
end
end %End of the first Loop
R(:) % hier i want to see all n values of (R)
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!