MATLAB: How to calculate the number of elements in a matrix

number of elements matrix

e.g having this matrix: M=[ 1 2 3; 7 8 9] I want to return 6 which is the total number of elements I want some other method besides size(M,1)*size(M,2). Thx

Best Answer

Use numel():
numberOfElements = numel(M);