Hi,
I am facing a problem when it comes to compare values of a variable with subscripts. Let me explain myself:
I have a variable Var1 which has a subscript [sub] and the subscript can take values from 1-100. When running the model a value will be calculated for Var1[sub1], Var1[sub2], ... etc. What I want to do is to calculate how many different values exist in all 100 realizations:
For example: if Var1[sub1]=3 , Var1[sub2]=7, Var1[sub3]=3 , then there exist 2 different values: 3 and 7.
In order to do that comparison, and avoid double counting, you have to compare each subscript to all consecutive ones: Var1[sub1] to Var[sub2-100] , ... Var1[sub50] to Var1[sub 51-100] and so on.
I am using the generic formula: IF THEN ELSE ( Var1[sub]=Var1[sub!], 1, 0 ) but it compares each value of the subscript to the entire range (including its own). Is there any way to ask [sub!] to take only its consecutive values? I have tried mapping but it requires to add another subscript and still go through hard-writing the mapping for all the range of [sub1].
Thanks for the tips!
Marios
Comparison using subscripts
comparison
Hi
The solution is first to order the array using the vector sort order and/or reorder function.
Once ordered one has just to compare each value to the value with just one order lower. If it is different one has to add 1 to the number of different values, 0 otherwise.
Regards.
JJ
[Edited on 12-2-2010 by LAUJJL]
[Edited on 12-2-2010 by LAUJJL]
The solution is first to order the array using the vector sort order and/or reorder function.
Once ordered one has just to compare each value to the value with just one order lower. If it is different one has to add 1 to the number of different values, 0 otherwise.
Regards.
JJ
[Edited on 12-2-2010 by LAUJJL]
[Edited on 12-2-2010 by LAUJJL]
Hi Laujjl,
Thanks for the prompt reply. Sorting does put them in an convenient order, but I still dont know how to ask it to compare to the value with one order lower (epsecially now that they have changed places in the array).
I realize this might be a trivial question, but I am not that an experienced user.
Thanks
Marios
Thanks for the prompt reply. Sorting does put them in an convenient order, but I still dont know how to ask it to compare to the value with one order lower (epsecially now that they have changed places in the array).
I realize this might be a trivial question, but I am not that an experienced user.
Thanks
Marios
ordering
The easiest to understand but less elegant is to define a variable called id[sub]= sub where sub is the subscript s1->s100
Then you have to compare vector[sub] with
vector elm map (vector[s1],id[sub] - 2) wich is the value just beneath the vector |sub].
Another way more elegant is to define two subranges s1->s99 and s2->s100 and define a mapping that transforms one into the other equivalent to decreasing the value of the subscript.
To understand that you must study the user and reference guides and take the time to study mapping. Take your time it is rather tricky.
Best
JJ
Then you have to compare vector[sub] with
vector elm map (vector[s1],id[sub] - 2) wich is the value just beneath the vector |sub].
Another way more elegant is to define two subranges s1->s99 and s2->s100 and define a mapping that transforms one into the other equivalent to decreasing the value of the subscript.
To understand that you must study the user and reference guides and take the time to study mapping. Take your time it is rather tricky.
Best
JJ