Scatter Plot of 2 dimensional vectors

28 vues (au cours des 30 derniers jours)
Hope
Hope le 28 Jan 2017
Hello!! I'm asking a question for my Machine Learning class.
The simple question is: how can I plot a collection of 2x1 vectors as points??
Here is the background information:
I have extracted 2 features and created a 2 by 1 vector (aka x = [feature1; feature2]) for each object being classified. Then, I stored each of these vectors in a cell array.
I have an array containing 7,000 2x1 feature vectors for Class 1 and I have another array containing 6,000 2x1 feature vectors for Class 2.
I would like to make a scatter plot of these 2x1 vectors, where data points (the vectors) from Class 1 are red and data points from Class 2 are green.
I've been attempting different scatter(), plot() functions, but none have outputted the result I need.
Thank you so much!!!

Réponses (2)

Walter Roberson
Walter Roberson le 29 Jan 2017
Modifié(e) : Walter Roberson le 29 Jan 2017
p1 = horzcat( Class1{:} ) .';
p2 = horzcat( Class2{:} ) .';
pointsize = 20;
h1 = scatter( p1(:,1), p1(:,2), pointsize, 'r');
hold on
h2 = scatter( p2(:,1), p2(:,2), pointsize, 'g');
hold off
legend( [h1, h2], {'Class 1', 'Class 2'})

mizuki
mizuki le 29 Jan 2017
Convert the cell array into double first with cell2mat. That makes easy for you to plot data. You can set the color of the data points with the third input argument of SCATTER.
x{1} = rand(2,1); % 2x1
x{2} = rand(2,1);
x{3} = rand(2,1);
y{1} = rand(2,1); % 2x1
y{2} = rand(2,1);
y{3} = rand(2,1);
% Convert cell to double
x_mat = cell2mat(x); % 2x3
y_mat = cell2mat(y); % 2x3
% plot data with scatter
figure
scatter(x_mat(1,:), x_mat(2,:))
hold on;
scatter(y_mat(1,:), y_mat(2,:), 'g')
hold off;
grid on;

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by