Macro language
Posted: Tue Jun 29, 2010 8:33 am
Hi,
I am trying to assign initial values in a proram using macro language loops. The initial values are specified in a standard vector. When trying to assing values to variables from the vector it doesn't work; see the simple example below, where Xsol is the vector, chi_@{i} a variable:
<START OF EXAMPE>
Xsol=[1 2 3 4 5 6 7 8 9];
@#define J = 9
@#for i in 1:(J-1)
var chi_@{i};
@#endfor
model;
@#for i in 1: J - 1
chi_@{i}=3;
@#endfor
end;
initval;
@#for i in 1:J-1
chi_@{i} = Xsol(i);
@#endfor
end;
<END OF EXAMPE>
The problem is that when trying to assign initial values, i get an error message
"??? Subscript indices must either be real positive integers or logicals."
due to the Xsol(i) term when assigning initial values (if replace Xsol(i) by, say 2 it works). How should this be done? In my general program the Xsol vector is large and there are several variables of the chi_@{i} type. Thus, it would be good if it is possible to use for loops when assingning initial values.
Andreas
I am trying to assign initial values in a proram using macro language loops. The initial values are specified in a standard vector. When trying to assing values to variables from the vector it doesn't work; see the simple example below, where Xsol is the vector, chi_@{i} a variable:
<START OF EXAMPE>
Xsol=[1 2 3 4 5 6 7 8 9];
@#define J = 9
@#for i in 1:(J-1)
var chi_@{i};
@#endfor
model;
@#for i in 1: J - 1
chi_@{i}=3;
@#endfor
end;
initval;
@#for i in 1:J-1
chi_@{i} = Xsol(i);
@#endfor
end;
<END OF EXAMPE>
The problem is that when trying to assign initial values, i get an error message
"??? Subscript indices must either be real positive integers or logicals."
due to the Xsol(i) term when assigning initial values (if replace Xsol(i) by, say 2 it works). How should this be done? In my general program the Xsol vector is large and there are several variables of the chi_@{i} type. Thus, it would be good if it is possible to use for loops when assingning initial values.
Andreas