Delete numbers that are not in both arrays

1 次查看(过去 30 天)
I have four arrays. I want to delete all the numbers that are not in all of the four arrays.
So for example:
A1 = [1 2 3 4 5]
A2 = [2 3 4 6 7]
A3 = [1 2 3 4 6]
A4 = [2 3 4 5 6]
I want to do the following automatically:
A1([1 5]) = [] --> A1 = [2 3 4]
A2([4 5]) = [] --> A2 = [2 3 4]
A3([1 5]) = [] --> A3 = [2 3 4]
A4([4 5]) = [] --> A4 = [2 3 4]
So I want to find the indices to delete the columns that I don't want.

回答(1 个)

Steven Lord
Steven Lord 2021-5-18
Use the intersect function a couple times. That will be easier if you define an array or a cell array of data rather than using numbered variable names.

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by