MATLAB: Extracting element values from a matrix in Simulink extract_elementsmatrixsimulink I have a covariance matrix P(k) that's [2×2] I want to read the values of the diagonal elements with a scope. I was wondering how this could be done? Best Regards, Shawn Daniel Best Answer You can use a selector block Related SolutionsMATLAB: 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. MATLAB: Extracting non-zero elements in a matrix or an array a=[1 0 2;3 4 5;0 7 8]a(a~=0) %get all the non zero valuesdiag(a) %elements on the diagonals1=sum(diag(a)) %sum of the elements on the diagonalsum(sum(a))-s1 %sum of non-diagonal elements Related QuestionElement by Element MultiplicationElement to element sumElement by Element SubtractionHow to write sparse matrix
Best Answer