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 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