How to refer to an subscript

Use this forum to post Vensim related questions.
Post Reply
hendrikstouten
Junior Member
Posts: 9
Joined: Mon Jun 25, 2007 9:13 am

How to refer to an subscript

Post by hendrikstouten »

I have a small problem. I have a matrix (= two dimensional array), for instance:


B1 B2 B3
-------------------------------
A1) 0 1 2
A2) 2 0 1
A3) 2 1 0

Given this matrix, I would like to refer for each A value to the subcript of B which has the lowest value in the matrix. Thus, For A1, the result should be 1 (from B1), since the cell A1-B1 = 0 and is the lowest value in the row A1.

For A2, the result should be 2 (from B2) and for A3, the result should be 3 from B3.

So, how can I refer to the 'index' of a subscript in a two (or multi-dimensional) array?

Can you help me solve this problem?

Thanks in advance.

Hendrik Stouten
Administrator
Super Administrator
Posts: 4838
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

Can you have a look at the attached model? I think does what you need (for a 2D array).

Tony.
Attachments
sort model.mdl
(1.85 KiB) Downloaded 811 times
hendrikstouten
Junior Member
Posts: 9
Joined: Mon Jun 25, 2007 9:13 am

Post by hendrikstouten »

Dear administrator,

Thanks for the help. Problem is solved.

Kind regards,

Hendrik
naserprs87
Junior Member
Posts: 13
Joined: Wed Jun 24, 2015 3:15 pm
Vensim version: DSS

Re:

Post by naserprs87 »

Administrator wrote:Can you have a look at the attached model? I think does what you need (for a 2D array).

Tony.
Dear Tony,
I would like to use an index of one subscript. My subscript which is named "Path" has 22 paths. I want to use a IF THEN ELSE function and say, for instance, just use subscripts 2,3, and 9.
Would you help me?
Administrator
Super Administrator
Posts: 4838
Joined: Wed Mar 05, 2003 3:10 am

Re: How to refer to an subscript

Post by Administrator »

I don't understand what you want to do. Can you upload an example?

Or is "VECTOR ELM MAP" the function you need?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
naserprs87
Junior Member
Posts: 13
Joined: Wed Jun 24, 2015 3:15 pm
Vensim version: DSS

Re: How to refer to an subscript

Post by naserprs87 »

Administrator wrote:I don't understand what you want to do. Can you upload an example?

Or is "VECTOR ELM MAP" the function you need?

I mean I have a subscript which has 22 different elements. Then, In an equation, like IF THEN ELSE, I want to refer to the 9th element.
How should I do that?
Administrator
Super Administrator
Posts: 4838
Joined: Wed Mar 05, 2003 3:10 am

Re: How to refer to an subscript

Post by Administrator »

Here is my range.

range : (element1-element100)

to get the 9th, you use

if then else ( range = 9 , ... , ... )

Or use VECTOR ELM MAP.
https://www.vensim.com/documentation/in ... lm_map.htm
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
LAUJJL
Senior Member
Posts: 1477
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: How to refer to an subscript

Post by LAUJJL »

Hi

I never use the vector elm map which is tricky especially with multiple subscripts.

If range is the subscript with values (r1-r100)

I define the variable subscripted ident[range] = range which will take the values 1 to 100.

Then if I have a variable subscripted like var[range] Vensim does not recognize var[9] for instance or var[r9]. You can use the vector elm map but I use var_r9 = sum(if then else( ident[range!] = 9,var[range],0)).

If you have say 3 subscripts
var_r9_s10_t8 = sum(if then else(ident[range!] = 9 :AND: ident[sange!] = 10
:AND: ident[tange!] = 8,var[range!,sange!,tange!],0) )
, if range, sange and tange are the three subscripts. It is much easer to write than the complex vector elm map sub,tub,gub etc.. Besides if there is an error in the vector elm map, there will be no error warning if the vector elm map goes outside of the interval where the values are stored.

Regards.

JJ
tomfid
Administrator
Posts: 3994
Joined: Wed May 24, 2006 4:54 am

Re: How to refer to an subscript

Post by tomfid »

VECTOR SELECT is another option. In many cases it should be a lot faster than an IF THEN ELSE statement, because it only visits the selected elements. However, I haven't tested to be sure, and it would only matter in a large model.

Example:

Code: Select all

myRange : (r1-r22)
active element[myRange] = 0,0,1,0,0,0,1,0,...
selective minimum = VECTOR SELECT( active element[myRange!], value[myRange!], missing value, operation, error setting )
where 'missing value' is what to do if there is no selection - you might set it to :NA:; operation is 0 for sum, 2 for minimum, etc.; error setting determines whether to flag problems when there are too few or many selections.
Post Reply