how to create multiple matrix from a single matrix
2 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Akira Agata
on 6 Jan 2020
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!