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
How to refer to an subscript
-
- Junior Member
- Posts: 9
- Joined: Mon Jun 25, 2007 9:13 am
-
- Super Administrator
- Posts: 4838
- Joined: Wed Mar 05, 2003 3:10 am
Can you have a look at the attached model? I think does what you need (for a 2D array).
Tony.
Tony.
- Attachments
-
- sort model.mdl
- (1.85 KiB) Downloaded 811 times
-
- Junior Member
- Posts: 9
- Joined: Mon Jun 25, 2007 9:13 am
-
- Junior Member
- Posts: 13
- Joined: Wed Jun 24, 2015 3:15 pm
- Vensim version: DSS
Re:
Dear Tony,Administrator wrote:Can you have a look at the attached model? I think does what you need (for a 2D array).
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?
-
- Super Administrator
- Posts: 4838
- Joined: Wed Mar 05, 2003 3:10 am
Re: How to refer to an subscript
I don't understand what you want to do. Can you upload an example?
Or is "VECTOR ELM MAP" the function you need?
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
-
- Junior Member
- Posts: 13
- Joined: Wed Jun 24, 2015 3:15 pm
- Vensim version: DSS
Re: How to refer to an subscript
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?
-
- Super Administrator
- Posts: 4838
- Joined: Wed Mar 05, 2003 3:10 am
Re: How to refer to an subscript
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
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: How to refer to an subscript
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
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
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:
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.
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 )
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/