how to repeat a loop?

조회 수: 5 (최근 30일)
arian hoseini
arian hoseini 2022년 6월 13일
댓글: Image Analyst 2022년 6월 16일
LD = [1 2 0.004 1 0.05i 0 100
1 3 0.0057 2 0.0714i 0 70
3 4 0.005 3 0.0563i 0 80
4 5 0.005 4 0.045i 0 100
5 6 0.0045 5 0.0409i 0 110
2 6 0.0044 6 0.05i 0 90
1 6 0.005 7 0.05i 0 100];
PTR= 150e3/110;
CTR= [240 240 160 240 240 240 160 240 160 240 240 240 240 160];
for i=1:7
% for n=8:14
z(i,1)=(LD(i,3)+LD(i,5))*LD(i,7);
% z(n,1)=(LD(i,3)+LD(i,5))*LD(i,7);
% end
theta = angle(z(i,1));
z = abs(z)
end
z = 5.0160
z = 2×1
5.0160 5.0139
z = 3×1
5.0160 5.0139 4.5217
z = 4×1
5.0160 5.0139 4.5217 4.5277
z = 5×1
5.0160 5.0139 4.5217 4.5277 4.5261
z = 6×1
5.0160 5.0139 4.5217 4.5277 4.5261 4.5174
z = 7×1
5.0160 5.0139 4.5217 4.5277 4.5261 4.5174 5.0249
% for i= 1:14
% zsz1(1,i) = ((z(i,1))/(cos((theta(i,1)-45)*pi/180))*(CTR(1,i)/PTR));
% end
i need my loop to repeat again i want answers to be exactly like the first seven z(i,1)...thank u
  댓글 수: 2
Sam Chak
Sam Chak 2022년 6월 13일
Do you mean to repeat the loop infinitely unless broken on Ctrl+C?
arian hoseini
arian hoseini 2022년 6월 13일
no sir i need them like this(14 ans)
5.0160
5.0139
4.5217
4.5277
4.5261
4.5174
5.0249
5.0160
5.0139
4.5217
4.5277
4.5261
4.5174
5.0249

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

채택된 답변

Image Analyst
Image Analyst 2022년 6월 13일
If you simply want to repeat the loop while printing out exactly the same values each time, then do this:
for k = 1 : 2
for i=1:7
z(i,1)=(LD(i,3)+LD(i,5))*LD(i,7);
theta = angle(z(i,1));
z = abs(z)
end
end

추가 답변 (1개)

dpb
dpb 2022년 6월 13일
편집: dpb 2022년 6월 13일
While you could, why not just duplicate the array as many times as needed once it's been generated --
z=repmat(z,2,1);
  댓글 수: 4
arian hoseini
arian hoseini 2022년 6월 16일
well thank u all ...first why do another loop?the ans is i have to calculate line impedance so i have 1 to 2 line and 2 to 1 line ..thats why i need this to be repeated as u see here
%n fromline toline impedance
B=[1 2 1 1 z(1)
2 1 3 2 z(2)
3 3 4 3 z(3)
4 4 5 4 z(4)
5 5 6 5 z(5)
6 6 2 6 z(6)
7 6 1 7 z(7)
8 1 2 1 z(1)
9 3 1 2 z(2)
10 4 3 3 z(3)
11 5 4 4 z(4)
12 6 5 5 z(5)
13 2 6 6 z(6)
14 1 6 7 z(7)];
Image Analyst
Image Analyst 2022년 6월 16일
If you have the left 4 columns of B already, you could just tack on two copies of z:
z = 1:7;
B=[1 2 1 1
2 1 3 2
3 3 4 3
4 4 5 4
5 5 6 5
6 6 2 6
7 6 1 7
8 1 2 1
9 3 1 2
10 4 3 3
11 5 4 4
12 6 5 5
13 2 6 6
14 1 6 7];
z2 = [z(:); z(:)];
B = [B, z2]

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

카테고리

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

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by