Pergunta

I have for example to following Matlab code.

A = [1/2 -1 1; -1/6 1/2 -1];
b = [sym('b',[2 1]); 1];
SOL = solve(A*b == zeros(2,1));

Now the solution, SOL, has two fields b1 and b2. I can access the solutions by typing SOL.b1 or SOL.b2. Now I want to loop through these two solutions. How can I do this? For example SOL.b(i)?

Foi útil?

Solução

Use dynamic field names:

for ii = 1:2
    SOL.(['b' num2str(ii)])
    %// do whatever with this
end
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top