Identify the mode in each column and eliminate them
Show older comments
I am curious to see if the following could be done without loops.
I have a 7-by-N matrix with all integers. In each column of the matrix, there is one integer that appears 4 time (hence the most frequent integer).
This there any way to eliminate the most frequent integers in every column and to output the rest of the integers in a 3-by-N matrix without using loops?
Example: a = [1 1 2 2 2 2 3; 1 2 2 2 2 3 3; 2 2 2 2 3 3 3]';
Output should be [1 1 3; 1 3 3; 3 3 3]'
The order of numbers in each column could be randomized unlike in my example. Thank you very much and no this is not a homework problem.
Accepted Answer
More Answers (2)
Iain
on 6 Jun 2013
a = a';
out = reshape(a(a~=2),[],3)';
That will work for your example, but not necessarily what you're dealing with.
Roger Stafford
on 7 Jun 2013
Let 'a' be an array in which one element of each row is repeated the same number of times for all rows with no other element in each row occurring as often as this.
b = a.';
b = reshape(b(bsxfun(@ne,mode(b),b)),[],size(b,2)).';
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!