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!