Page 1 of 1

Period of variable signal

Posted: Fri Jul 03, 2009 2:35 pm
by yusuke
Hello
I'm using vensim professional version.

I make a variable which has a signal "0" or "1".
For example (starttime =1 , endtime =10)
time 1 2 3 4 5 6 7 8 9 10
var 0 0 0 1 1 1 1 1 0 0

I want to get the period which var = 1.
In this case , time(8) - time(4)+1=5
It is the same of the count which var(value) =1

Thank you for your help.
Yusuke Tarumoto

Posted: Sat Jul 04, 2009 9:43 am
by bob@vensim.com
The period of time since a variable last changed can be computed using

time unchanged = Time - last change time
last change time = SAMPLE IF TRUE(ABS(var-old var) > tolerance, var,Time,INITIAL TIME)
old var = SMOOTH(var,TIME STEP)

This will start counting again from 0 when the variable changes, so I am not sure if that is exactly what you want.

Posted: Sun Jul 05, 2009 3:01 am
by yusuke
Thank you ,Bob.

I try to use [SAMPLE IF TRUE] function in a model.
But I can't. My troble is [last change time].
> last change time = SAMPLE IF TRUE(ABS(var-old var) > tolerance, var,Time,INITIAL TIME)

I attach a sample model .

Best regards

Posted: Sun Jul 05, 2009 11:22 am
by bob@vensim.com
The model does what I would expect it to. I think I do not understand what you want to see.

period of variable signal

Posted: Mon Jul 06, 2009 9:59 am
by LAUJJL
Hi

If I understand what you want (hence the utility of being clear about what one wants), you are interested in knowing the number of periods where var is equal to 1?
If it is what you want, the model joined is extremely simple and does the job.
Regards.
JJ

Posted: Wed Jul 08, 2009 10:41 pm
by yusuke
Thank you LAUJJL .
Your model spanvalue[2] is just one i need.

The using of equation <Time Step>/<Time Step> is effective for unit check.

I thank bob , too.