In MATLAB, let's say I have a set of square matrices, say A, with trace (A) = 0 as follows:
For instance,
A = [0 1 2; 3 0 4; 5 6 0]
How can I remove zeros and then vertically collapse the matrix so that it looks like this:
A_reduced = [1 2; 3 4; 5 6]
More generally, what if zeros can appear anywhere in a column (i.e., not necessarily on a long diagonal)? Assuming, of course, that the total number of zeros is the same for all columns.
The matrix can be quite large (hundreds to hundreds in size). Thus, an effective method will be appreciated.
Val k source
share