How can I create sub matrix from a whole matrix

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?

 Accepted Answer

Jan
Jan on 3 Apr 2017
Edited: Jan on 3 Apr 2017
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

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 3 Apr 2017

Edited:

Jan
on 3 Apr 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!