Counting the maximum occurrence of an element in 3d matrix ?

I have a matrix of dimensions (61x61x122) or (lat,lon,days), which has 0 and 1 values for random days.
I want to calculate the value of maximum occurrence of 1 for each grid (lat,lon).

 Accepted Answer

sum(3dmatrix==1,[1,2])
% for older versions
sum(sum(3dmatrix==1,2),1)

4 Comments

Thank you madhan for your concern.
Let me specify my question more.
let's say
A=int16(rand(3,3,8));
I want to count number of ones on each grid of the matrix (3x3) for whole period until any zero comes, and then want to store it in a matrix, and at last, to find the maximum value among the resultants, if you get it
v = squeeze(sum(threedmatrix==1,[1,2]));
nv = v(cumprod(v~=0)==1);
Max = max(nv)

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!