How to "vectorize" this operation?
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
Hi,
I have data of sample size m of n by n matrices in an n by m*n matrix call it P.
I also have a function, call if f, that operates on a fixed vector, call it v, and n by n matrices.
I want to to create a 1 by m vector, call it d, by operating f on v and each of the n by n matrices in P.
So, say for example, n = 3 and m = 6 I would want:
d(1) = f(v,P(:,1:3)), d(2) = f(v,P(:,4:6)), . . ., d(6) = f(v,P(:,16:18))
How can I do this without making a loop?
Thanks!
3 comentarios
Matt J
el 12 de Abr. de 2013
Whether that's possible would depend on the form of f().
Peter Laslo
el 12 de Abr. de 2013
Respuestas (1)
Matt J
el 12 de Abr. de 2013
This looks like it avoids a for-loop, but doesn't really.
P=reshape(P,n,n,m);
d= arrayfun(@(i) f(v,P(:,:,i)) , 1:m);
1 comentario
Peter Laslo
el 12 de Abr. de 2013
Editada: Peter Laslo
el 12 de Abr. de 2013
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!