How do I add elements to a structure in a loop?
Afficher commentaires plus anciens
I'm trying to fit a number of polynomials to x/y, and want to save the results of each fit so I can evaluate which is best. So...
for norder = 2:2:highestOrder [p,S,mu] = polyfit(x,y,norder); end
I'd like a structure 'poly' to be able to store 'p', 'S', and 'mu' for each iteration of the for loop. Ideally the structure would look like poly.p2, to poly.phighestOrder, poly.S2...
How would I do that?
Réponse acceptée
Plus de réponses (1)
ANKUR KUMAR
le 20 Sep 2018
Just simple store separated with dot. Example
for ii=1:15
[a,b,c]=polyfit(randi(20,1,100),randi(10,1,100),2)
poly{ii}.a=a;
poly{ii}.b=c;
poly{ii}.c=c;
end
1 commentaire
Kim
le 20 Sep 2018
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!