1
votes

I am trying to solve a large system of linear equations in matlab (about 3600 equations!) Since the number of variables is too many, I have to define them in a matrix. So I use this code to define the variables:

A = sym('A',[60,60]);

It has to be a 60x60 matrix because the variables correspond to a finite difference problem (i.e. a mesh grid).

After writing the corresponding equations in a for loop, I use the solve function in this way:

mysol = solve(eq,A);

Where eq is the equations matrix.

My problem is that, when I try to solve this system as shown in MATLAB help, i.e. writing something like this:

C(1,1) = mysol.A(1,1)

I get an error that says: "Reference to non-existent field 'A'". But if I write something like:

C(1,1) = mysol.A1_1

then it works.

Does anyone know how I can fix this? I don't want to do this for every variable!

1

1 Answers

2
votes

You could try accessing the fields in the structure dynamically like so:

for ii = 1:60
    for jj = 1:60
        field = sprintf('A%d_%d', ii, jj);
        C(ii, jj) = mysol.(field);
    end
end