matlab中出现多个循环问题

时间:2017-11-15 10:09:45

标签: matlab signal-processing

很抱歉提出非常基本的问题,但我在多个循环中感到困惑。

我想同时运行所有循环,然后打破循环并转到R, e and x combine的下一循环。

Means for R =1 ,e=1 ,x=1 and then R=2 ,e=2 ,x=2 and so on.

有人可以告诉我我的错在哪里或者缺少什么来获得我想要的结果吗?

代码:

 threshold = [0.4:0.1:1.1];       
 limit_for_idx  = [0.4:0.1:1.1]; 
 limit = [0.4:0.1:1.1];            


 D=1;
 E=1;
 J=0;
  for R = 1:numel(threshold);  
      for e = 1:numel(limit_for_idx);
          for x = 1:numel(limit)

          J = J+1 ;
          % Perform Tasks and go to next loop for R ,e and x           
          break
      end
        break
    end
  end

1 个答案:

答案 0 :(得分:0)

您的代码中的错误是在第二次迭代中依此类推,ex将再次获得1,而不是2或您的值想。

要解决这个问题,只需迭代一个变量并将它们全部等于它:

threshold = [0.4:0.1:1.1];       
limit_for_idx  = [0.4:0.1:1.1]; 
limit = [0.4:0.1:1.1];            
D=1;
E=1;
J=0;
for R=1:numel(threshold)
   e=R;
   x=R;
   % do your stuff...
end