Trying to find values within a struct with a case

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

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 14 de Mayo de 2020
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 comentarios

Alex Davison
Alex Davison el 15 de Mayo de 2020
This worked, thank you!
Ameer Hamza
Ameer Hamza el 15 de Mayo de 2020
I am glad to be of help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Centro de ayuda y File Exchange.

Preguntada:

el 14 de Mayo de 2020

Comentada:

el 15 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by