如何创建一个自动显示程序输出的循环

时间:2012-11-27 06:38:27

标签: matlab octave

在我的程序中,假设我没有修复。用户N=6。 SIR SIRo=6的阈值;生成的输出为SIRmean=10(假设)。

我想制作一个循环以便

if SIRmean < SIRo

   disp N=6

else

  decrease the counter till SIRmean> SIRo
   and display the value of N for which this condition holds true.

end

1 个答案:

答案 0 :(得分:0)

你可以使用简单的for循环与downcounter并在条件下中断:

N=6;
for k=N:-1:0
   SIRmean = calc_SIR_mean(N);
   if SIRmean < SIRo
      disp(['N=' k])
      break;
   end
end

函数calc_SIR_mean应根据用户数返回平均值(从您的问题中不清楚如何获得此值)。