how to repeat a loop?
显示 更早的评论
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
% 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
2022-6-13
Do you mean to repeat the loop infinitely unless broken on Ctrl+C?
arian hoseini
2022-6-13
采纳的回答
更多回答(1 个)
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 个评论
Image Analyst
2022-6-13
Or, once it's been generated once, just use z. Why do another loop just to do the very same thing? Or replicate another identical row? I don't see the point of either.
dpb
2022-6-13
Well, agreed it's not clear "why" at all here, indeed, but... :)
I presumed there was something else going to happen later that needed the size to be 2X the initial size. It's not at all unusual to end up duplicating data to match some other array size for later array or vector or matrix operations.
Of course, we see lots of instances where beginners duplicate stuff needlessly, too, ...
arian hoseini
2022-6-16
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]
类别
在 帮助中心 和 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!