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

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 14일
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

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

질문:

2020년 5월 14일

댓글:

2020년 5월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by