Reputation: 23
I have two vectors x
and y
.
I want to plot them both as coordinates, ex: (x1,y1) ; (x2,y2)
, with a dot representing each point. I can't figure out how to do it.
I tried to use the use the meshgrid
function but it didn't work out.
Upvotes: 1
Views: 5519
Reputation: 426
If you intend to plot them as vectors from the origin, MATLAB's plotv
function (which comes with the Neural Network toolbox) allows you to do just that.
The following should work:
M = [x1 x2 ; ...
y1 y2];
plotv(M)
You can find the documentation at the MATLAB plotv page.
If, however, you wish to plot only the points, you may use a scatter plot. You could use the following:
X = [x1 x2];
Y = [y1 y2];
scatter(X, Y)
The documentation of the scatter plot may be found at the MATLAB scatter page.
If you intend to plot a vector from (x1, y1) to (x2, y2), the following, using MATLAB's quiver
function, should help:
quiver(x1,y1,(x2 - x1),(y2 - y1),0)
Please find the documentation for quiver
on this page. In the example I discussed, the 0
is for turning off automatic scaling.
Upvotes: 3
Reputation: 1511
Why this didn't work?
plot(x,y,'o','MarkerFaceColor','b'); axis square; hold on
best
Upvotes: 0
Reputation: 3001
You may want to take a look at Paul Mennen's plt
package on the File Exchange.
This includes an auxillary function Pquiv
(documented here) that allows the plotting of vectors.
An example picture is at this location, with the source code available for that plot as one of the 'demo' files.
The documentation for this project is very good, and although I'm still trying to get used to the setup, it does help with a lot of plotting related issues in Matlab.
The author (email address available after installation by using help plt
) is also quick to respond to questions that people have, some of which are also visible in the comments on File Exchange.
Upvotes: 1