我在vb中有这个函数,我想在matlab中编写。有谁知道如何使用for循环而不是goto关键字编写?
FOR i = 1 TO 101
X(i) = (i - 1) * .5 / 50:
X(i) = X(i) / 2 / PI / F:
NEXT i
j = 6
870 FOR i = 1 TO 100
IF X(i) <= j * .005 AND X(i + 1) >= j * .005 THEN GOTO 890 ELSE GOTO 1000
890 AZ4(j) = AY4(i) + (AY4(i + 1) - AY4(i)) / (X(i + 1) - X(i)) * (j * .005 - X(i))
BZ4(j) = BY4(i) + (BY4(i + 1) - BY4(i)) / (X(i + 1) - X(i)) * (j * .005 - X(i))
CZ4(j) = CY4(i) + (CY4(i + 1) - CY4(i)) / (X(i + 1) - X(i)) * (j * .005 - X(i))
DZ4(j) = DY4(i) + (DY4(i + 1) - DY4(i)) / (X(i + 1) - X(i)) * (j * .005 - X(i))
EZ4(j) = EY4(i) + (EY4(i + 1) - EY4(i)) / (X(i + 1) - X(i)) * (j * .005 - X(i))
AZT(j) = AYT(i) + (AYT(i + 1) - AYT(i)) / (X(i + 1) - X(i)) * (j * .005 - X(i))
BZT(j) = BYT(i) + (BYT(i + 1) - BYT(i)) / (X(i + 1) - X(i)) * (j * .005 - X(i))
CZT(j) = CYT(i) + (CYT(i + 1) - CYT(i)) / (X(i + 1) - X(i)) * (j * .005 - X(i))
DZT(j) = DYT(i) + (DYT(i + 1) - DYT(i)) / (X(i + 1) - X(i)) * (j * .005 - X(i))
EZT(j) = EYT(i) + (EYT(i + 1) - EYT(i)) / (X(i + 1) - X(i)) * (j * .005 - X(i))
i = 101
1000 NEXT i
j = j + 1
IF j * .005 > X(101) THEN GOTO 1040
GOTO 870
1040 FOR i = 1 TO 126
AY4(i) = AZ4(i): BY4(i) = BZ4(i): CY4(i) = CZ4(i): DY4(i) = DZ4(i): EY4(i) = EZ4(i)
AYT(i) = AZT(i): BYT(i) = BZT(i): CYT(i) = CZT(i): DYT(i) = DZT(i): EYT(i) = EZT(i)
NEXT i
FOR i = 1 TO 126
X(i) = i * .005
NEXT i
答案 0 :(得分:2)
我将只编写代码的框架,其余的语句必须由您完成。我将使用ii
和jj
代替i
和j
,因为它们在MATLAB(-1的复数平方根)中具有特殊含义。
for ii = 1:101
% statements
end;
jj = 6;
while true
for ii = 1:100
if (cond1) && (cond2) % replace with actual conditions
% statements from label 890
break;
end;
end;
ii = 101; % useless, but...
jj = jj+1;
if cond3 % replace with actual condition
break;
end;
end;
for ii = 1:126
% statements
end;
for ii = 1:126
% statements
end;