Removing unique numbers whilst comparing two structures
显示 更早的评论
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 个评论
Jan
2019-4-25
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
2019-4-25
Please attach AllPositions_CA in a .mat file with the paper clip icon.
Also, see Stephen's answer below.
Manny Kins
2019-4-25
编辑:Manny Kins
2019-4-25
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!