MATLAB: Compute centroid of a matrix centroid how to compute centroid of a matrix? is it possible? Best Answer If you have the Image Processing Toolbox,regionprops(true(size(matrix)), matrix, 'WeightedCentroid');Otherwise,matrix=matrix/sum(matrix(:));[m,n]=size(matrix);[I,J]=ndgrid(1:m,1:n); centroid=[dot(I(:),matrix(:)), dot(J(:),matrix(:))] Related SolutionsMATLAB: Parallel Matrix row operation function out = Proj_DoubleStochasticM_reloc(Y,sparsity) [m,n]=size(Y); [I,J]=deal(sparsity); for k=1:length(sparsity) I{k}(:)=k; end I=cell2mat(I); J=cell2mat(J); bw=sparse(I,J,true,m,n); Y=Y.*bw; out=Y-bw.*(sum(Y,2)-1)./sum(bw,2); %EDITEDend MATLAB: Access Diagonal Matrix Element As it is a rectangular matrix you will get 15 diagonal(i=j) elements. If you have a square matrix of size nxn, you will get n diagonal elements. Related QuestionCalculating centroidsTriangle centroidHow can i separate all the connected regions in a binary image and display them individually.Plotting centroid values
Best Answer