Vectorize two for loops
1 回表示 (過去 30 日間)
古いコメントを表示
How to vectorize this function:
for i=1:100
for j=1:200
TheOne(i,j) = i+j;
end
end
0 件のコメント
回答 (2 件)
David Hill
2020 年 11 月 19 日
編集済み: David Hill
2020 年 11 月 19 日
[i,j]=meshgrid(1:100,1:200);
TheOne=reshape(sum((Png1(:,i)-Png2(:,j)).^2),100,[]);
4 件のコメント
David Hill
2020 年 11 月 19 日
Made a mistake. Try this.
[i,j]=meshgrid(1:100,1:200);
TheOne=reshape(sum((Png1(:,i)-Png2(:,j)).^2),200,[])';
CHENG QIAN LAI
2020 年 11 月 24 日
[i,j]=ndgrid(1:100,1:200);
% 1 2 3 . . . 200
%---------------------------
% i= 1 1 1 . . . 1 | 1
% 2 2 2 . . . 2 | 2
% 3 3 3 . . . 3 | 3
% . . . | .
% . . . | .
% . . . | .
% 100 100 100 . . . 100 | 100
%---------------------------
% j= 1 2 3 . . . 200 | 1
% 1 2 3 . . . 200 | 2
% 1 2 3 . . . 200 | 3
% . . . | .
% . . . | .
% . . . | .
% 1 2 3 . . . 200 | 100
TheOne = i+j;
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!