Page 1 of 1

Change a specific element of an array

Posted: Wed Feb 20, 2013 6:00 pm
by agroe
Hi,

I am trying to select and change only one element of an array which satisfies a certain condition even if there are several elements within this array which satisfy that condition. For example, I have the following array v=(-1,-1,0,0,0) in which two elements equal -1 (the condition). However, I only want to change one of the two elements which equal -1 to zero and leave the other unchanged (i.e., v'=(0,-1,0,0,0) or (-1,0,0,0,0)). How can I do this in Vensim?

Thanks a lot!

Re: Change a specific element of an array

Posted: Wed Feb 20, 2013 8:16 pm
by tomfid
Here's a way:
ss map iter 1.mdl
(1.91 KiB) Downloaded 367 times
Note the subscript mapping of iPrev & iNext - this is the standard way to iterate over subscript elements.

Re: Change a specific element of an array

Posted: Wed Feb 20, 2013 11:34 pm
by agroe
That's a very nice and elegant way! Thanks a lot!