how to create multiple matrix from a single matrix

2 次查看(过去 30 天)
If i have a matrix A=[ 1 2 3, 4 5 6, 7 8 9, 0 0 0, 0 0 0, 10 11 12, 13 14 15, 0 0 0, 0 0 0, 16 17 18 upto 10000 points]
here 1 2 3 are coordinates x y z .
so I want to store data in such a way that when we find two rows of all zeros there should be a new matrix created.
we need output like:
B1=[1 2 3, 4 5 6, 7 8 9]
B2=[10 11 12, 13 14 15]
B3=[16 17 18, .....]
B4= so on... upto last point of A.

采纳的回答

Akira Agata
Akira Agata 2020-1-6
If you have Image Processing Toolbox, how about the following?
% Sample data
A = [...
1 2 3;...
4 5 6;...
7 8 9;...
0 0 0;...
0 0 0;...
10 11 12;...
13 14 15;...
0 0 0;...
0 0 0;...
16 17 18];
% Create label array
idx = ~all(A==0,2);
label = bwlabel(idx);
% Split the matrix A based on the label
c = splitapply(@(x){x}, A(idx,:), label(idx));
In this case, c{1}, c{2},....,c{N} corresponds to your desired mabrix B1, B2,...,BN.

更多回答(0 个)

产品


版本

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by