How to filter structured array by several conditions

조회 수: 10 (최근 30일)
Dwayne
Dwayne 2018년 8월 16일
편집: dpb 2018년 8월 16일
I have a structure array containing many fields such as size, perimeter, euler angles. I would like to filter this by calculations I have made to filter the euler angles within to having a misorientation angle (in euler space) of maximum 20 degrees to three different euler space points. I would then like to filter the entire structured array to only contain values which meet this condition.
For example,
if Data is the structured array, within this I have an array - Data.meanOrientation. Within this is Data.meanOrientation.phi, Data.meanOrientation.phi1, Data.meanOrientation.phi2. I would like to filter all of Data to only include the values which have the euler angles within 20 degrees of defined conditions.
For example, one condition is 0, 45 and 0 degrees for phi,phi1,phi2 and I want to select only Data which is within 20 degrees of these three. I then have another condition, but I want to select Data which corresponds to either the first and/or this second condition. I would then like to proceed with calculations on a DATA array which only corresponds to either of these conditions only while ignoring the rest of the data set which is not useful to me.
Any tips regarding which approach I should take would be most helpful.
Apologies if this is not clear, thank you for your time.

채택된 답변

dpb
dpb 2018년 8월 16일
편집: dpb 2018년 8월 16일
I'd start be suggesting to rearrange the data struct--instead of using three fields with different names for associated data, have one array and reference the three elements by column index. Your variable would then be
Data.meanOrientation.phi % phi is Nx3 array
With this your lookup is very easy to write...first define you target angle vector
A=[0 45 0]; % in application use a(1), a(2), a(3) to set on demand
tol=20; % set the angle tolerance
isIn=~ismembertol(Data.meanOrientation.phi,A,tol,,'ByRows',1,'DataScale',1); % those not in tolerance by row
Data=Data.meanOrientation.phi(isIn,:); % return desired subset
The above uses the fixed tolerance for each column, it is also possible to set by column as well. See
doc ismembertol
for details and further use.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by