Concise way to remove columns of a matrix with at least 2 repeating values in separate rows

1 visualizzazione (ultimi 30 giorni)
Hello again,
I am currently trying to find an elegant way to code in a function that would remove columns based on repeating values in at least 2 rows in that one column. I have read about "unique" function but i'm not certain how to code in all the arguments so i'm getting what i wanted. I have made a graphic example of what i would like to achieve below.
This is just an example of a matrix with 3 rows but ultimately i want to have this option be realisable for N number of rows so it can't be fixed.
Best regards and thank you for any help,

Risposta accettata

Matt J
Matt J il 20 Mar 2023
Modificato: Matt J il 20 Mar 2023
One possibilty,
A =[
2 8 1 8 2 3
1 7 5 4 5 4
2 6 3 1 8 4]; %hypothetical input
discard=any(diff(sort(A,1),1,1)==0);
A(:,discard)=[]
A = 3×4
8 1 8 2 7 5 4 5 6 3 1 8

Più risposte (0)

Categorie

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

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by