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!