How can I replace for loop with meshgrid?
9 ビュー (過去 30 日間)
古いコメントを表示
For example,
a = zeros(20,100);
b = rand(20,100);
for m = 2:20
for n = 2:100
a(m,n)=b(m-1,n)+1;
end
end
Using FOR loops is not efficient.
Can loops be replaced with meshgrid?
Thank you.
0 件のコメント
回答 (1 件)
madhan ravi
2019 年 3 月 23 日
編集済み: madhan ravi
2019 年 3 月 23 日
You don't need a meshgrid to do the task:
[ m, n ] = size( b );
d = zeros( m, n );
d( 2 : m, 2 : n ) = b( 1 : end - 1, 2 : end ) + 1
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!