How to use "FOR" correctly in this example?

1 view (last 30 days)
[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 Comments
vinicius lanziotti
vinicius lanziotti on 10 Jun 2018
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 on 10 Jun 2018
If k and i must change at the same time, then why not use i=k ?

Sign in to comment.

Answers (0)

Categories

Find more on Electrical and Computer Engineering in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!