Faster than for loop?
Mostrar comentarios más antiguos
I presently have this code which tests a paricular function which I created _ _ [y n] function_gen1pdf1(a,b,c) _ _ for N times. Now this works fine up to N=100. However, I want it to work for N=100,000 but it's taking much too long to compute. Is it possible to vectorize it or make it work faster? Any suggestions are much appreciated!
N=100000;
y=zeros(N,1);
n=zeros(N,1);
for i=1:N; %testing the function for 100000 times
[y(i) n(i)]= function_gen1pdf1(2,3,0.5); %The function being tested
end
7 comentarios
Star Strider
el 7 de Feb. de 2015
Please post the function code!
Stephen23
el 7 de Feb. de 2015
"Is it possible to vectorize it": this depends entirely on the function function_gen1pdf1. If you want help trying to vectorize this, then you have to upload its code too.
Geoff Hayes
el 7 de Feb. de 2015
rox - I don't understand the line
[y(i) n(i)]= function_gen1pdf1(2,3,0.5);
You keep calling function_gen1pdf1 with the same set of inputs for every i. Why is the code repeating the same call at every iteration of the for loop?
Tapan
el 7 de Feb. de 2015
I will echo everyone else's comments - you need to provide the function code. Perhaps try a parlor loop in the meantime.
Jan
el 7 de Feb. de 2015
@Geoff: The "gen" in the name might mean a genetic algorithm, such that random effects can be the reasn for different results inspite of the same inputs.
Image Analyst
el 7 de Feb. de 2015
Or maybe it generates a PDF document, or generates a probability distribution function. Whatever it does, apparently PDF does not mean "Pretty Darn Fast".
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!