フィルターのクリア

split a matrix into two matrices according to some rule

3 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2024 年 2 月 12 日
コメント済み: Cris LaPierre 2024 年 2 月 12 日
How can I generate two separate matrices, one containing the coordinates of line A and the other of line B?
load matrix
figure
plot3(matrix(:,1),matrix(:,2),matrix(:,3),'k.','Markersize',5);
axis equal
grid off
I wanted to try this way but it does not seem the best way.
% range
xRange = [xmin xmax];
yRange = [ymin ymax];
zRange = [zmin zmax];
% indices of points in the range
idx = matrix(:,1) >= xRange(1) & matrix(:,1) <= xRange(2) & ...
matrix(:,2) >= yRange(1) & matrix(:,2) <= yRange(2) & ...
matrix(:,3) >= zRange(1) & matrix(:,3) <= zRange(2);
select_matrix = [matrix(idx,1), matrix(idx,2), matrix(idx,3)];
  5 件のコメント
Alberto Acri
Alberto Acri 2024 年 2 月 12 日
Hi Stephen! sorry, I realised I had not installed 'Image Processing Toolbox'!
Alberto Acri
Alberto Acri 2024 年 2 月 12 日
I wanted to know if there is a way to get the subdivision! I don't have any 'rules' at the moment!

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

採用された回答

Cris LaPierre
Cris LaPierre 2024 年 2 月 12 日
編集済み: Cris LaPierre 2024 年 2 月 12 日
I would look into clustering. Here is an attempt that uses dbscan, a spectral clustring algorithm included in the Statistics and Machine Learning Toolbox.
You can learn more about this and other clustering techniques in our Practical Data Science with MATLAB specialization on Coursera. It's free to enroll. Here is a link to the video Introdcution to Clustering Algorithms.
load matrix.mat
% view the raw data
plot3(matrix(:,1),matrix(:,2),matrix(:,3),'k.','Markersize',5);
% use dbscan to identify clusters
idx = dbscan(matrix,1.5,5);
gscatter(matrix(:,1),matrix(:,2),idx)
  1 件のコメント
Cris LaPierre
Cris LaPierre 2024 年 2 月 12 日
If you know the number of clusters already, use spectralcluster.
load matrix.mat
idx = spectralcluster(matrix,2);
gscatter(matrix(:,1),matrix(:,2),idx)

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

その他の回答 (0 件)

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by