Determining which values are found in all columns of an array

Hello,
I have data in an array (1x35) each col have multiple rows of varying number. I would like to go through each of the 35 cols in the array and see which values occur throughout all or at least 30. Any idea how I would do this?
Thanks!

댓글 수: 2

This means you have a cell array of size 1-by-35, where each cell holds a column vector (1 column) with a varying number of elements?
Correct. Sorry for the semantics.

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

 채택된 답변

Jos (10584)
Jos (10584) 2014년 2월 25일
Assuming you matrix is a cell array:
% create some example data
CVFun = @(n) ceil(10*rand(n,1)) ; % helper function to create some data
C = {CVFun(10) CVFun(4) CVFun(7) CVFun(9) CVFun(10) CVFun(12)} % a 1-by-6 cell array
% engine
unVal = unique(cat(1,C{:})) ; % get all unique values in C
isPresent = cellfun(@(x) ismember(unVal,x),C,'un',0)
isPresent = cat(2,isPresent{:}) ;
Count = sum(isPresent,2) % count in how many columns a unique value is found
[MaxCount, idx] = max(Count)
[unVal(idx) MaxCount] % the (most likely) result

댓글 수: 4

Thanks Jos,
This won't pull out more than one value would it? For instance, when I ran it, ans was [2,5] which would mean that 2 was the most probable in all cols with a max count of 5 correct? Would this then do this for other values with a high count?
the value 2 occurs indeed in 5 columns. There might be other numbers that occur in 5 columns, though, but there are no numbers that occur in more than 5 columns. To get all these values, use this after the […]=max(…) statement
tf = Count == MaxCount
[unVal(tf) Count(tf)]
Is there any use of "histc()" function?
in what sense? You can use histc to count how many times elements occur
A = [1 3 5 2 4 3 4 4 1 6 7 5 6]
unA = unique(A)
N = histc(A,unA)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2014년 2월 25일

댓글:

2014년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by