Along with 3 numeric values the data contains categorical value (0 or 1) and would like to display the data using 3D scatter plot. I have tried to write a function to read the data from csv file and create a scatter plot the following way:
function f = ScatterPlotUsers(filename)
data = ReadCSV(filename);
x = data(:,2);
y = data(:,3);
z = data(:,4);
size = ones(length(x), 1)*20;
userType = data(:,5);
colors = zeros(length(x), 1);
a = find(userType == 1);
b = find(userType == 0);
colors(a,1) = 42; %# color for users type a
colors(b,1) = 2; %# color for users type b
scatter3(x(:),y(:),z(:),size, colors,'filled')
view(-60,60);
What I actually wanted to do was to set the colour for a to red and b to blue but no matter the colour values (42 and 2 in example) the colours of dots don’t change.
Does anyone know what is the right way to determine specific colours for several categorical values (in this case only 0 and 1)?
You are doing it right, however, are you sure the colormap entries 42 and 2 refer to red and blue? You could try to give RGB values explicitly:
Also, I’d advise you to change the name of the variable
size, sincesizeis also a Matlab command; Matlab might be confused about that, and any future readers of your code will certainly be confused about that.