MATLAB: Calculations or sum all diagonal elements sum diagonal elements hi. to sum all diagonal elements i used sum(diag(a)) know; if i want to sum first 170 elements or last 80 elements, how can i do this. Best Answer FirstN = @(V,N) V(1:N);LastN = @(V,N) V(end-N+1:end);sum(FirstN(diag(a), 170))sum(LastN(diag(a), 80)) Related SolutionsMATLAB: How to Sum matrix diagonals sum(diag(a(:,end:-1:1)));or summing all diagonals:sum(spdiags(rot90(a))); MATLAB: How to sum only few values in a diagonal matrix Rida, use sum(diag(A(1:3,1:3))) Related QuestionFind summation of all the element in the matrixHow to pad empty cells with the last number in the rowIs there a function to sum 1:n matrices of same sizeExtracting non-zero elements in a matrix or an array
Best Answer