How do I make an array of numbers in the titles of a structure?

9 vues (au cours des 30 derniers jours)
Frank Oosterveld
Frank Oosterveld le 8 Nov 2018
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 1x1 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?

Réponse acceptée

Adam
Adam le 8 Nov 2018
Modifié(e) : Adam le 8 Nov 2018
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.

Plus de réponses (0)

Catégories

En savoir plus sur Functions dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by