Macro language


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:

Xsol=[1 2 3 4 5 6 7 8 9];

@#define J = 9

@#for i in 1:(J-1)

var chi_@{i};



@#for i in 1: J - 1



@#for i in 1:J-1

chi_@{i} = Xsol(i);


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.


I figured out the answer: use Xsol(@{i}) instead of Xsol(i). Of course…