Speed up logical operations
Mostrar comentarios más antiguos
I am working on a problem: an array of sub-systems(over hundreds) , each has two states [0 1].
The pre-defined probability transition between are p1(0->1) and p2 (1->0)
The whole system is evolving with time, I am trying to use the logical operations to update the system state:
given an array of random number generated (pn)
SubSysState(SubSysState==0)=(p1(SubSysState==0)>pn(SubSysState==0))
SubSysState(SubSysState~=0)=(p2(SubSysState~=0)<pn(SubSysState~=0))
I did the 'Profiler' on the code, the above operations are lines where the most time was spent.
I am just wondering if there any other way to speed up it or anyone has better idea to do it?
Thanks a lot
Respuestas (1)
Sean de Wolski
el 2 de Mayo de 2011
Compute the logical conditions only once:
SubSysStateeq0 = SubSysState==0;
SubSysStateneq0 = ~SubSysStateeq0;
SubSysState(SubSysStateeq0)=(p1(SubSysStateeq0)>pn(SubSysStateeq0))
SubSysState(SubSysStateneq0)=(p2(SubSysStateneq0)<pn(SubSysStateneq0))
1 comentario
Feng
el 2 de Mayo de 2011
Categorías
Más información sobre Elementary Math 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!