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에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!