Why in the code given below the number of iterations of the second - for loop ('j') decreases at each iteration of first - for loop ('l')?
    5 ビュー (過去 30 日間)
  
       古いコメントを表示
    
 for l=1:N-1 
      disp(['l: ',num2str(l)])
        for j=1:N-l
            disp(['j: ',num2str(j)])
            length = length+1;
        end
end
The output iterations are showing like this. Why 'j' is decreasing at each iteration of 'l'?
l: 1
j: 1
j: 2
j: 3
j: 4
j: 5
j: 6
j: 7
j: 8
j: 9
l: 2
j: 1
j: 2
j: 3
j: 4
j: 5
j: 6
j: 7
j: 8
l: 3
j: 1
j: 2
j: 3
j: 4
j: 5
j: 6
j: 7
l: 4
j: 1
j: 2
j: 3
j: 4
j: 5
j: 6
l: 5
j: 1
j: 2
j: 3
j: 4
j: 5
l: 6
j: 1
j: 2
j: 3
j: 4
l: 7
j: 1
j: 2
j: 3
l: 8
j: 1
j: 2
l: 9
j: 1
0 件のコメント
採用された回答
  VBBV
      
      
 2023 年 6 月 6 日
        For each iteration of I , the j counter is reduced by N- I  instead of N-1 
N = 5;
length = 0;
for I=1:N-1 
      disp(['l: ',num2str(l)])
      %   ------>> I 
        for j=1:N-I
            disp(['j: ',num2str(j)])
            length = length+1;
        end
end
1 件のコメント
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Signal Processing Toolbox についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

