How to call a function with rows of a matrix?
3 ビュー (過去 30 日間)
古いコメントを表示
Hey,
I would like to vectorize a function call that I call with rows of a matrix. How can I implement it without a for loop?
Thanks.
5 件のコメント
回答 (2 件)
the cyclist
2014 年 10 月 30 日
編集済み: the cyclist
2014 年 10 月 30 日
Res = zeros(10000,1);
for looper=1:10000
Res(looper) = aFunction(Mat(looper,:),Mat2(looper,:))
end
Note that the first line, preallocating memory is important for the loop to operate efficiently.
If you want to post your aFunction code, it might be possible to identify a way to eliminate the loop entirely.
0 件のコメント
Stephen23
2014 年 10 月 30 日
編集済み: Stephen23
2014 年 10 月 30 日
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!