How to speed up this code?
Informazioni
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Mostra commenti meno recenti
I'm trying to speed up a code made of several functions and, when I run the profiler, I see that the function that takes the most time is the following in this part.
n=size(Amat,2);
for k=1:size(Amat,1)
cv(k,1)= copula_Clayton(Amat(k,1:n),alpha_0);
end
Is it possible to eliminate that for loop and make the copula_Clayton func run on every row of the matrix Amat(k,1:n) automatically?
1 Commento
José-Luis
il 22 Lug 2014
Two things:
- Pre-allocate cv
- Re-write copula_Clayton to that it takes the whole Amat as input.
Please note that since we have no way of guessing at what copula_Clayton actually does, it is very difficult for us to suggest possible improvements.
Risposte (1)
Azzi Abdelmalek
il 22 Lug 2014
Modificato: Azzi Abdelmalek
il 22 Lug 2014
You can use arrayfun, but you will notice that the for loop is faster.
cv=arrayfun(@(k) copula_Clayton(Amat(k,1:n),alpha_0),(1:size(Amat,1))','un',0);
1 Commento
Giacomo
il 22 Lug 2014
Questa domanda è chiusa.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!