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
Sean de Wolski 2011년 5월 2일

0 개 추천

Compute the logical conditions only once:
SubSysStateeq0 = SubSysState==0;
SubSysStateneq0 = ~SubSysStateeq0;
SubSysState(SubSysStateeq0)=(p1(SubSysStateeq0)>pn(SubSysStateeq0))
SubSysState(SubSysStateneq0)=(p2(SubSysStateneq0)<pn(SubSysStateneq0))

댓글 수: 1

Feng
Feng 2011년 5월 2일
Thank you, Sean
It did speed up a little. I should have thought about it.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Elementary Math에 대해 자세히 알아보기

질문:

2011년 5월 2일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by