Filter löschen
Filter löschen

Delete numbers that are not in both arrays

1 Ansicht (letzte 30 Tage)
Dylan den Hartog
Dylan den Hartog am 18 Mai 2021
Beantwortet: Steven Lord am 18 Mai 2021
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.

Antworten (1)

Steven Lord
Steven Lord am 18 Mai 2021
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.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by