MATLAB: How to make an array of numbers in the titles of a structure

fprintfMATLABstructures

I have the following problem, I have the following set of equations including symbolic terms,
eq = K*U == F;
I solved the set of equations according to,
FU_antwoord = solve(eq,[F(1), U(2), U(3), U(4)]);
This provides me with an 1×1 struct with 4 fields (FU_antwoord), now I want to convert these to numerical values:
u2 = double(FU_antwoord.U2);
u3 = double(FU_antwoord.U3);
u4 = double(FU_antwoord.U4);
This works, but I'll have an arbitrary number elements U's (U5, U6, …). I tried to work with fprintf, to eventually double these expressions, but this did not work.
for i = 1:N_elements
FPF = fprintf('M_antwoord.U%1.0f\n', i)
end
What is a more constructive way of retrieving the numerical values from a structure with an arbitrary number of elements?

Best Answer

for n = 1:numel(U)
u(n) = double( FU_antwoord.( ['U' num2str(n + 1)] ) )
end
will put them in an array. Creating an arbitrary number of individual variables is not a good idea at all.
doc struct2array
may work too, more simply.