How to call a function with rows of a matrix?
Ältere Kommentare anzeigen
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 Kommentare
the cyclist
am 29 Okt. 2014
There is not remotely enough detail here to answer. Think from our perspective on this.
UCL student
am 30 Okt. 2014
UCL student
am 30 Okt. 2014
Antworten (2)
the cyclist
am 30 Okt. 2014
Bearbeitet: the cyclist
am 30 Okt. 2014
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.
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!