Create a boundary of real numbers in a two dimentional matrix consisting of nan and real numbers

1 view (last 30 days)
I have the organized point cloud data measured by Lidar.
That data is two dimentinal matrix consisting of nan and real numbers.
I want to divide the data by clutering with real number boundary.
Does this algorithm exist in the past? Or Is there a code like that?
Finally, I want to separate the obstacles' information.
  2 Comments
익환 류
익환 류 on 29 Nov 2022
a = [nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan;...
nan nan nan 0.5 0.5 0.5 0.5 nan nan nan nan nan nan 0.5 0.5 0.5 nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan;...
nan nan nan 0.5 0.5 0.5 0.5 nan nan nan nan nan nan 0.5 0.5 0.5 nan nan nan nan nan 0.5 0.5 0.5 nan nan nan 0.5 nan nan nan nan;...
nan nan nan 0.5 0.5 0.5 0.5 nan nan nan nan nan nan 0.5 0.5 0.5 nan nan nan nan nan 0.5 0.5 0.5 0.5 0.5 0.5 0.5 nan nan nan nan;...
nan nan nan 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 nan nan nan nan nan 0.5 0.5 0.5 nan nan nan 0.5 nan nan nan nan;...
nan nan nan 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 nan nan nan nan nan nan nan nan nan nan nan 0.5 nan nan nan nan;...
nan nan nan 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan;...
nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan];

Sign in to comment.

Answers (1)

Kartik
Kartik on 21 Mar 2023
Hi,
Yes, there are several algorithms in MATLAB that you can use to cluster the Lidar data based on real number boundaries. One approach you can use is the 'k-means' clustering algorithm. Here's an example code to get you started:
% Replace NaN values with zeros
a(isnan(a)) = 0;
% Set the number of clusters you want to create
num_clusters = 2;
% Perform k-means clustering
[idx, C] = kmeans(a(:), num_clusters);
% Reshape the clustered data to its original shape
idx = reshape(idx, size(a));
This code uses k-means clustering to create two clusters from the Lidar data. The 'kmeans' function takes the flattened data '(a(:))' and the number of clusters as input and returns the cluster indices '(idx)' and the centroid values '(C)'. The 'reshape' function is used to reshape the clustered data to its original shape.
You can adjust the number of clusters to match your needs. Note that the clustering result might not be perfect, especially if the data has a lot of noise or if the clusters are not well-separated. You might need to experiment with different clustering algorithms and parameters to get the best result for your data.

Community Treasure Hunt

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

Start Hunting!