how to create multiple matrix from a single matrix

2 visualizaciones (últimos 30 días)
Akshay Sahu
Akshay Sahu el 6 de En. de 2020
Comentada: Akshay Sahu el 6 de En. de 2020
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.

Respuesta aceptada

Akira Agata
Akira Agata el 6 de En. de 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.

Más respuestas (0)

Etiquetas

Productos


Versión

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by