How to use "FOR" correctly in this example?

1 回表示 (過去 30 日間)
vinicius lanziotti
vinicius lanziotti 2018 年 6 月 10 日
コメント済み: Walter Roberson 2018 年 6 月 10 日
[l,~]=size(barras);
for k=1:quant_barras
if k<=9 && SAIDA_FP(k,2)>=0
for i=1:l
if SAIDA_FP(k,1) >= barras(i,7) && SAIDA_FP(k,1) <= barras(i,8)
fprintf(arquivo,'O módulo da tensão da Barra %d está dentro da faixa pré-especificada. \r\n',k);
else
fprintf(arquivo,'O módulo da tensão da Barra %d NÃO está dentro da faixa pré-especificada. \r\n',k);
end
end
end
end
===>>> OUTPUT THAT I NEDD:
O módulo da tensão da Barra 1 está dentro da faixa pré-especificada.
O módulo da tensão da Barra 2 está dentro da faixa pré-especificada.
O módulo da tensão da Barra 3 está dentro da faixa pré-especificada.
O módulo da tensão da Barra 4 NÃO está dentro da faixa pré-especificada.
  4 件のコメント
vinicius lanziotti
vinicius lanziotti 2018 年 6 月 10 日
The way the code was made, for k=1 we have 4 iterations of i, for k=2, 4 iterations of i... I want just 1 iteration of i for each k!
for k=1, i=1;
for k=2, i=2;
for k=3, i=3; (...)
Walter Roberson
Walter Roberson 2018 年 6 月 10 日
If k and i must change at the same time, then why not use i=k ?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeElectrical and Computer Engineering についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by