J.Smith
J.Smith

Reputation: 335

Same value must exist at least 3 times in a Matrix

The matrix <1x500> consists of different values, now I want to check if any of the values in the matrix occurs at least 3 times or more.

if (val occurs  3 times or more)
   do

Help is very appreciated!

Upvotes: 0

Views: 49

Answers (2)

Ander Biguri
Ander Biguri

Reputation: 35525

Another option from @KiW answer for when you need to know all the values that do appear at least 3 times is:

uniqA=unique(A);
counts=histcounts(A,[uniqA inf]);
vals_that_are_bigger=uniqA(counts>=3);

To check if any of them are bigger than 3, just

if any(counts>=3)

Upvotes: 6

KiW
KiW

Reputation: 593

if numel(find(matrix)==val)>3
whatever you want to do
end

Upvotes: 1

Related Questions