フィルターのクリア

how to create multiple matrix from a single matrix

1 回表示 (過去 30 日間)
Akshay Sahu
Akshay Sahu 2020 年 1 月 6 日
コメント済み: Akshay Sahu 2020 年 1 月 6 日
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.
  1 件のコメント
Akshay Sahu
Akshay Sahu 2020 年 1 月 6 日
Thank you Sir Akira Agata.

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by