MATLAB: How to get the mode of a 3d-array 3d arraymodemost frequent valuesmrivolumetric image Dear experts, how do I get the mode of a 3D array with dim [51 75 55]. It can only contain numbers from 0:12 and I'm not interested in the zeros. Best Answer mode(nonzeros(yourArray)), Related SolutionsMATLAB: Delete a dimension from a 3d array to convert into a 2d array (Matrix) squeeze(yourarray)orpermute(yourarray, [2 3 1])squeeze is simpler and will get rid of all singleton dimensions. MATLAB: How to reduce the computation time for adding 3D-array You can reformulate the loop as convolution ofA = accumarray([x(:) y(:) z(:)]-length(Small)/2,1,[500 500 500])andB = flip(flip(flip(Small,1),2),3)(I left out the detail of overflowed for simplicity)You might look at convn function. The problem I see is that A is sparse (1/125 in density) and might not be efficient as for loop.You also might try this FEX to see if you can exploit the sparsityhttps://www.mathworks.com/matlabcentral/fileexchange/41310-sparse-matrix-convolutionOr this one using different method of compute convolutionhttps://www.mathworks.com/matlabcentral/fileexchange/24504-fft-based-convolution Related QuestionCreating a 2D matrix of non-zero modes from a 3D arrayAveraging the 3D-arrayCell Mode
Best Answer