Page 1 of 1
How to refer to an subscript
Posted: Mon Jun 25, 2007 2:38 pm
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
Posted: Tue Jun 26, 2007 9:13 am
by Administrator
Can you have a look at the attached model? I think does what you need (for a 2D array).
Tony.
Posted: Thu Jun 28, 2007 4:01 pm
by hendrikstouten
Dear administrator,
Thanks for the help. Problem is solved.
Kind regards,
Hendrik
Re:
Posted: Mon Feb 22, 2016 10:29 pm
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?
Re: How to refer to an subscript
Posted: Mon Feb 22, 2016 11:41 pm
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?
Re: How to refer to an subscript
Posted: Tue Feb 23, 2016 2:34 pm
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?
Re: How to refer to an subscript
Posted: Tue Feb 23, 2016 2:42 pm
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
Re: How to refer to an subscript
Posted: Tue Feb 23, 2016 5:17 pm
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
Re: How to refer to an subscript
Posted: Tue Feb 23, 2016 10:56 pm
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.