Change a specific element of an array

Use this forum to post Vensim related questions.
Post Reply
agroe
Junior Member
Posts: 9
Joined: Sun Feb 10, 2013 8:32 pm
Vensim version: DSS

Change a specific element of an array

Post 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!
tomfid
Administrator
Posts: 3995
Joined: Wed May 24, 2006 4:54 am

Re: Change a specific element of an array

Post 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.
agroe
Junior Member
Posts: 9
Joined: Sun Feb 10, 2013 8:32 pm
Vensim version: DSS

Re: Change a specific element of an array

Post by agroe »

That's a very nice and elegant way! Thanks a lot!
Post Reply