In MATLAB, say I have a set of square matrices, say A, with trace(A)=0 as follows:
For example,
A = [0 1 2; 3 0 4; 5 6 0]
How can I remove the zeros and then vertically collapse the matrix to become as follow:
A_reduced = [1 2; 3 4; 5 6]
More generally, what if the zeroes can appear anywhere in the column (i.e., not necessarily at the long diagonal)? Assuming, of course, that the total number of zeros for all columns are the same.
The matrix can be quite big (hundreds x hundreds in dimension). So, an efficient way will be appreciated.
A = [0 3 0 2; 3 0 0 1; 7 0 6 0; 1 0 6 0;0 16 0 9]? - Divakar"total number of zeros for all columns are the same"condition and state the desired output? For example something like this has two zeros in every column -A = [0 3 7 1 0;3 0 0 0 6; 0 0 6 5 0;3 2 0 0 6], so what must be the expected output for this case? - DivakarA_reducedassumes the number of zeros in all rows is the same, and then can you compress horizontally. So your question is confusing. Anyway, I think my answer convers the two possibilities - Luis Mendo