Removing unique numbers whilst comparing two structures
Show older comments
I have two structs, one called AllPositions_CA with X and Y fields containing this type of layout:
X Y
1x17051 double 1x17051 double
1x17267 double 1x17267 double
1x17579 double 1x17579 double
1x17971 double 1x17971 double
1x17959 double 1x17959 double
1x17947 double 1x17947 double
1x17854 double 1x17854 double
1x641 double 1x641 double
1x17918 double 1x17918 double
1x17544 double 1x17544 double
This structure has a length 114 (I have only shown 10)
I have a second structure called PositionA which has X and Y fields containing this type of layout:
X Y
1x42 double 1x42 double
1x44 double 1x44 double
1x43 double 1x43 double
1x43 double 1x43 double
1x44 double 1x44 double
1x43 double 1x43 double
1x43 double 1x43 double
1x43 double 1x43 double
1x44 double 1x44 double
1x42 double 1x42 double
This particular structure has length of 18000 (I have only shown 10)
I want to be able to take ALL X and Y values as pairs in AllPositions_CA and compare them to X and Y pair values in PositionA and remove any values which are present in PositionA but are not present in AllPositions_CA and put them into a new structure whilst retaining the layout of the structure PositionA. For example after the removal of some values from PositionA the new structure will look like:
X Y
1x40 double 1x40 double
1x39 double 1x39 double
1x41 double 1x41 double
1x40 double 1x40 double
1x42 double 1x42 double
1x41 double 1x41 double
1x39 double 1x39 double
1x40 double 1x40 double
1x43 double 1x43 double
1x38 double 1x38 double
I have looked into intersect and setdiff but cannot get my head around how to loop one structure through another to find differences and return the desired final layout as above.
Thanks
3 Comments
Jan
on 25 Apr 2019
I've read this sentence mutliple times:
I want to be able to take ALL values in AllPositions_CA and compare them to each value in PositionA and remove any values which are present in PositionA but are not present in AllPositions_CA and put them into a new structure whilst retaining the layout of the structure PositionA
It would be easier to use the names A and B instead of AllPositions_CA and PositionA. But even then it does not get clear to me, what you want to achieve.
Do you want to remove all elements of the fields PositionA.X and positionA.Y which occur anywhere in AllPositions_CA.X and AllPositions_CA.Y? Or do the X/Y pairs play a rule, such that PositionA.X(k)(m) and PositionA.Y(k)(m) should be removed only, if they occur in AllPositions_CA.X(k)(n) and PositionA.Y(k)(n)?
A small example would be useful. Use A and B with 2 or 3 elements to clarify what you want.
Image Analyst
on 25 Apr 2019
Please attach AllPositions_CA in a .mat file with the paper clip icon.
Also, see Stephen's answer below.
Manny Kins
on 25 Apr 2019
Edited: Manny Kins
on 25 Apr 2019
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!