how to plot two matrices in the same window in matlab in different graphs and colors?
-
13-12-2019 - |
Question
figure;
plot(trainingSet(:, 1), trainingSet(:, 2), '*');
figure;
plot(reprVectors(:, 1), reprVectors(:, 2), '*');
How do I plot the points from trainingSet and reprVectors in same figure instead of 2 different ones?
Also How can I make trainingSet pts blue and reprVectors points red?
Solution
What you describe is the subplot function: same figure, different plot axes
eg:
c=-2:0.1:2;
figure
subplot(121)
plot(x,x);
subplot(122)
plot(x,x.^2)
This plots the function y=x and y=x^2 in one figure, but next to eachother.
The red/blue and marker options are already explained in other answers :)
OTHER TIPS
I would do it with the MATLAB Hold Function
The syntax would be:
figurel
plot(trainingSet(:, 1), trainingSet(:, 2), '*');
hold on
plot(reprVectors(:, 1), reprVectors(:, 2), '*');
hold off
Hope that helps
If you replace the second figure
by hold on
, they will be plotted together. You can add color identifiers to the marker, for example plot(....,...,'r*')
will plot red stars and 'bo'
plots blue circles. The available shapes and colors are described here.