# How do I create a 2-D plot with a matrix that contains data points and a matrix that contains class labels?

13 visualizaciones (últimos 30 días)
Nicholas el 5 de Sept. de 2022
Respondida: Walter Roberson el 6 de Sept. de 2022
I would like to create a 2-d plot where the data points come from one matrix called features (8000x2). Column 1 contains the x values and column 2 contains the y values. I have worked out something that works here:
f = features;
c = classlabels;
plot(f(:,1),f(:,2),'x')
xlabel('Feature 1')
ylabel('Feature 2')
Now I also have a matrix called classlabels (8000x1). Each row contains a value 1 or 2 which idicate the class. Row one of classlabels corresponds to data point one, row two corresponds to data point two and so on. How can I incorporate the classlabels matrix such that I can change the shape/color of the data points obtained from the features matrix to make the classes 1 and 2 identifiable when plotted?
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Abolfazl Chaman Motlagh el 6 de Sept. de 2022
one simple way is to plot (scatter) every class separately.
f = rand(150,2);
C = randi(2,150,1);
scatter(f(C==1,1),f(C==1,2),'r','o');hold on;
scatter(f(C==2,1),f(C==2,2),'b','+');
legend('Class 1','Class 2');
if class are string or categorical or ... use correct logical equality in argument of f instead.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Más respuestas (1)

Walter Roberson el 6 de Sept. de 2022
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Numeric Types en Help Center y File Exchange.

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by