Delete numbers that are not in both arrays

1 visualizzazione (ultimi 30 giorni)
Dylan den Hartog
Dylan den Hartog il 18 Mag 2021
Risposto: Steven Lord il 18 Mag 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.

Risposte (1)

Steven Lord
Steven Lord il 18 Mag 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.

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by