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

1 view (last 30 days)
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,

Accepted Answer

Matt J
Matt J on 20 Mar 2023
Edited: Matt J on 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

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!