how to create multiple matrix from a single matrix
조회 수: 1 (최근 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.
댓글 수: 0
채택된 답변
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!