打印for for循环

时间:2017-02-16 06:59:41

标签: matlab for-loop

我有一个从1到1000的for循环。我想只在循环中打印问题的第8,第16和第64个解决方案。我怎么做?我是matlab的新手,所以如果你有帮助,你可能会尽可能简单。

3 个答案:

答案 0 :(得分:0)

如果您只是在寻找第8,16和64位,只需将if语句放入for循环中。

for k=1:1000
    if k == 8
        solution on the 8th run    
    elseif k == 16
        solution on the 16th run    
    else if k == 64
        solution on the 64th run
    else
        solution for all other runs (leave out if not needed)
    end
end

答案 1 :(得分:0)

这是一个真正的问题吗?

for ii=1:1000
   if ii=8
       //print here
   end
   if ii=16
       //print here
   end
end

答案 2 :(得分:0)

不是很大的改进,但你也可以做到这一点。

for  ii=1:1000
      if ii==8 || ii==16 || ii==64
             //print solution
      end 
end 
相关问题