MATLAB: How to access and modify only the non diagonal entries in a matrix matrix hello.. i hv a question. what is the command to call the non diagonal entries of a matrix? tq very much… Best Answer Please try the following: M = 8; N = 5; X = randn(M,N); idx = eye(M,N); Y = (1-idx).*X; Z = X(~idx);HTH.Best, RickResponding to your comment:To multiply the non-diagonal elements by 2, please try: A = [2 3 5;3 6 8;5 8 4]; idx = eye(size(A)); idx = idx + 2*(1-idx); Y = idx.*A;HTH.Best, Rick Related SolutionsMATLAB: How to create a program that reads a matrix array and returns me a second matrix composed of zeros and the main diagonal of the first matrix b = diag(diag(a)); MATLAB: How to get the diagonal and a subdiagonal in the same matrix A=[ 1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]B=triu(A)-triu(A,2)B = 1 2 0 0 0 6 7 0 0 0 11 12 0 0 0 16 Related QuestionExtracting non-zero elements in a matrix or an arrayHow to make sure that if creating a diagonal matrix from another, the matrices are the same sizeEigenvalues and orthonormal eigenvectorsHow to Sum matrix diagonals
Best Answer