MATLAB: How to create sub matrix from a whole matrix

matrix manipulation

Hi, I have a matrix [ 0 0 1 0.5 0.5 1 0 0 0 1 0 0 1 0 0 0 0 1 0.5 0.5 0.5 1 0 0 0 1]…I want to extract "0" portions as matrix as [0 0],[0 0 0], [0 0], [0 0 0 0] and [ 0 0 0]..How to do this?

Best Answer

x = [ 0 0 1 0.5 0.5 1 0 0 0 1 0 0 1 0 0 0 0 1 0.5 0.5 0.5 1 0 0 0 1];
[B, N, XI] = RunLength(x);
Is0 = (B == 0);
ini = XI(is0);
fin = ini + N(is0) - 1;
The k's zero block goes from ini(k) to fin(k).
Do you really want to get a cell array containing the subvectors? It seems like an expensive data representation.
N0 = N(is0);
C = cell(1, numel(N0));
for iC = 1:numel(N0)
C{iC} = zeros(N0(iC));
end