how to represent clusters graphicaly ?

1 visualización (últimos 30 días)
zyad
zyad el 12 de Mzo. de 2014
Respondida: Prateekshya el 14 de Oct. de 2024
hi,i want to implement LDA algorithm ,for a first step i want to have a graphical representation of clusters for example:represent those 2 groups X1=[4,2;2,4;2,3;3,6;4,4] and X2=[9,10;6,8;9,5;8,7;10,8] and X3=[......] with different colors in one graph? like in picture

Respuestas (1)

Prateekshya
Prateekshya el 14 de Oct. de 2024
Hello Zyad,
To graphically represent clusters using MATLAB, you can plot each group of data points with a different color. This will help you visualize how the data is distributed before applying the Linear Discriminant Analysis (LDA) algorithm. Here is how you can plot the example groups , , and with different colors:
% Define the data points for each group
X1 = [4, 2; 2, 4; 2, 3; 3, 6; 4, 4];
X2 = [9, 10; 6, 8; 9, 5; 8, 7; 10, 8];
X3 = [5, 5; 6, 5; 7, 6; 5, 7; 6, 6]; % Example data for X3
% Create a new figure
figure;
hold on; % Hold on to plot multiple groups on the same graph
% Plot each group with a different color and marker
plot(X1(:, 1), X1(:, 2), 'ro', 'MarkerSize', 8, 'DisplayName', 'Group X1'); % Red circles
plot(X2(:, 1), X2(:, 2), 'bs', 'MarkerSize', 8, 'DisplayName', 'Group X2'); % Blue squares
plot(X3(:, 1), X3(:, 2), 'g^', 'MarkerSize', 8, 'DisplayName', 'Group X3'); % Green triangles
% Add labels and legend
xlabel('Feature 1');
ylabel('Feature 2');
title('Graphical Representation of Clusters');
legend show; % Display the legend
grid on;
axis equal; % Ensure equal scaling of axes
hold off; % Release the hold on the current figure
The output of the code looks like:
I hope this helps!

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by