MATLAB:如何在带索引的for循环中进行比较

时间:2015-03-14 15:40:09

标签: arrays matlab for-loop vector

在for循环结束时,我想比较I(i)和I(j)的值,看第二个for循环。  这是返回的错误: ???试图访问I(2); index因界而错,因为numel(I)= 1。

==>中的错误如果(I(i)== I(j)&&(j< i))

,则在143处消除相位

请看下面的代码:

 alpha= 10;
       W=1;
       I=1;
       for i=1:N
              if (~ismember(num2str(i), num2str(F)))
                     while((C(i) < alpha) && (W < N))
                           if ((i~=W) && (ismember(W, neighbour_n{i})))
                               C(i)=C(i)+C(W);
                               display(['la somme des cardinaux de ', num2str(i), ' is   ', num2str(C(i))]);
                               I(i)=I(i)+1;
                               display(['The number of iteration of  ', num2str(i), ' is   ', num2str(I(i))]);
                               W=W+1;
                           else
                               W=W+1;
                           end  
                     end
              end
              if (~ismember(num2str(i), num2str(F)))
              display(['the value of the node:  ', num2str(i), '   at the end of while is ;  ', num2str(C(i))]); 
              end
       end
% l need to retreive the all the values of I and compare between them and between thein indices
   for i=1:N
         for j=1:N
             if (((~ismember(num2str(i), num2str(F)))&&(~ismember(num2str(i), num2str(F))))&&(i~=j))
                if (I(i)==I(j)&&(j < i))
                    display(i);
                end 
                 if (I(i) >I(j))
                    display(i);
                 end 
             end
         end  
     end

0 个答案:

没有答案