필터 지우기
필터 지우기

Identify the mode in each column and eliminate them

조회 수: 2 (최근 30일)
Han
Han 2013년 6월 6일
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.
  댓글 수: 1
Han
Han 2013년 6월 7일
Edit: I used number 1,2 and 3 just for my example. The integers could be different. There could be different "mode" numbers (the most frequent numbers) in different columns.

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 6월 6일
편집: Andrei Bobrov 2013년 6월 7일
reshape(a(ismember(a,[1,3])),[],size(a,2));
or
hankel([1 1 3],[3 3 3]);
ADD
s = size(a);
b = ones(s);
idxl = fliplr(triu(b,1) + tril(b,diff(s))) > 0;
out = reshape(a(idxl),[],s(2));
  댓글 수: 2
Han
Han 2013년 6월 7일
Number 1,2 and 3 only appeared in my example. It does not mean they should be the ones you use in your code.
Andrei Bobrov
Andrei Bobrov 2013년 6월 7일
See ADD part in my answer.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Iain
Iain 2013년 6월 6일
a = a';
out = reshape(a(a~=2),[],3)';
That will work for your example, but not necessarily what you're dealing with.
  댓글 수: 1
Han
Han 2013년 6월 7일
Number 1,2 and 3 only appeared in my example. It does not mean they should be the ones you use in your code.

댓글을 달려면 로그인하십시오.


Roger Stafford
Roger Stafford 2013년 6월 7일
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)).';

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by