Speed up logical operations
이전 댓글 표시
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
답변 (1개)
Sean de Wolski
2011년 5월 2일
Compute the logical conditions only once:
SubSysStateeq0 = SubSysState==0;
SubSysStateneq0 = ~SubSysStateeq0;
SubSysState(SubSysStateeq0)=(p1(SubSysStateeq0)>pn(SubSysStateeq0))
SubSysState(SubSysStateneq0)=(p2(SubSysStateneq0)<pn(SubSysStateneq0))
카테고리
도움말 센터 및 File Exchange에서 Elementary Math에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!