Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Looping/Conditional statements when I don't know the exact end point

1 Ansicht (letzte 30 Tage)
Pranav Thiagarajan
Pranav Thiagarajan am 18 Jan. 2017
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Hello,
I have an array that contains multiple points in 3D space. These points have been grouped into clusters based on their proximity to one another. The number of clusters aren't always constant. There could be multiple or no clusters in a set of data(i.e. clusters or just individual points). I need to plot these points on a 3D graph and assign colours based on the cluster(i.e. one specific coulr per cluster) and one cluster for lone points. The array works in the following way:
Columns 1,2,3 : X,Y,Z coordinates
Column 4: Cluster number that point has been assigned to (-1 for individual point and 1,2,3 etc. for that cluster, 0 does not exist)
Since I do not know how many clusters exist in the data set to begin with (I find it out later), how can I assign individual colors when I do not know how many I will need?
I have tried in the following way, but I think there has to be a better way to do this. My method visits each point multiple times based on how many clusters exist. Is there a better way that only visits each point once?
Thanks for any help.
Pranav
for i=-1:1:numofClusters
for j=1:rows
if targetinfo(j,4)==i
if i==-1
scatter3(targetinfo(j,1),targetinfo(j,2),targetinfo(j,3)...
,'k' ,'*') %noise
else
scatter3(targetinfo(j,1),targetinfo(j,2),targetinfo(j,3)...
,cm(i,:),'o') %point in cluster
end
end
end
end

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by