Hello,
I am working to extract the values of a 1x9 Struct (named FMtest) with 5 fields (named alpha, gamma, Fy, Fz, Mz). I need to find each measurement where alpha is 0 and then fit it to find further values (Cfa and Fy0 in my code
idx = find([FMtest(1:9).alpha] == 0);
pfy = polyfit(FMtest(1:9).alpha(idx),FMtest(1:9).Fy(idx),1);
Cfa = pfy(1)
Fy0 = pfy(2)
idx is returned as [53,156,259,361,463,565,667,769,871] which I am assuming corresponds to the array indicies where alpha is 0.
However, I am running into the following errors when trying to fit this case back on the struct
Errors:
Expected one output from a curly brace or dot indexing expression, but there were 9 results.
Error in RVD_Assignment4 (line 26)
pfy = polyfit(FMtest(1:9).alpha(idx),FMtest(1:9).Fy(idx),1);
Thank you,
Alex

 Réponse acceptée

This indexing format is not correct according to MATLAB format. You should do something like this
x1 = [FMtest(1:9).alpha];
x2 = [FMtest(1:9).Fy];
idx = find(x1 == 0);
pfy = polyfit(x1(idx), x2(idx), 1);

2 commentaires

This worked, thank you!
I am glad to be of help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Identification 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!

Translated by