MATLAB Answers

Classifiying the data points

2 views (last 30 days)
Hi i have a data set such as;
[x y z d], (100x4) matrices
x,y and z are coordinates and the d is the measure of a distance.Every d is corresponding with one point (x, y, z)
I want to create 10 classes from d and colorize the points (x,y,z) according to this classes and plot it
is anyone have idea?
Thank you

  0 Comments

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 2 Jul 2019
Try kmeans with 10 classes, and operating on the d values:
data = rand(100, 4)
x = data(:, 1);
y = data(:, 2)
z = data(:, 3);
d = data(:, 4);
numClasses = 10
% Find classes based on 4th column.
indexes = kmeans(d, numClasses);
% Make up a colormap with 10 colors
cmap = jet(10);
% Assign a color to each data point based on it's class
markerColors = zeros(10, 3); % 10 colors.
for k = 1 : size(data, 1)
thisClassNumber = indexes(k)
markerColors(k, :) = cmap(thisClassNumber, :);
end
scatter3(x, y, z, 50, markerColors, 'filled');
fontSize = 20;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
zlabel('Z', 'FontSize', fontSize);
0000 Screenshot.png
There is a marker at each (x,y,z) location and its color depends on which of the 10 classes that point's "d" value got classified into.

  10 Comments

Show 7 older comments
Image Analyst
Image Analyst on 4 Jul 2019
You added a space after "filled". It makes a difference. Somehow when you were altering the line of code I gave you, you added the space.
If you use 'filled ' instead of 'filled' then you will get the error you got. If you don't, you won't get the error.
Mehmet Volkan Ozdogan
Mehmet Volkan Ozdogan on 4 Jul 2019
Thank you for the answer. the problem was space. Now it is working. I have one more question, is it possible to add a legend abour classification...
thank you again for your helps
Image Analyst
Image Analyst on 4 Jul 2019
I think you'd have to do it manually with text().

Sign in to comment.

More Answers (0)

Sign in to answer this question.