I have a binary matrix like this:
0 0 0 0 0 0
0 0 0 1 0 0
0 1 0 0 0 0
0 0 1 0 1 0
0 0 0 1 0 0
0 0 0 0 0 0
and I want to crop this matrix (in other words, remove zeros at the borders) so that it looks like this:
0 0 1 0
1 0 0 0
0 1 0 1
0 0 1 0
How to do Matlab? that do not use regular loops and conditions .
To be more precise , the matrix should be reduced to start with the first column, which has at least one 1, and ends in the last column with the same condition, inclusive. Any column in this range must be removed. For strings, the same rules apply.
Thank.
source
share