How to use "FOR" correctly in this example?

1 次查看(过去 30 天)
[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 CenterFile Exchange 中查找有关 Electrical and Computer Engineering 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by