Avoid the usage of eval when you need a fast program, and in all other cases also.
Instead of creating the strings 'theta(1).*theta(1)' it would be smarter to store the indices only:
A = {[1,1], [1,2], [1,3]; ...
[2,1], [2,2], [2,3]; ...
[3,1], [3,2], 3,3]};
for i = 1:n
for j = 1:n
index = A{i, j};
a(i,j) = theta(index(1)) * theta(index(2));
end
end
Using a numerical 3D array might be even faster.
Creating files dynamically has the big disadvantage, that reading and parsing the M-files is very time-consuming. Matlab is much more efficient, if you use static M-files and vary the parameters only.
Best Answer