简体   繁体   中英

Plotting coordinates with vectors on matlab

I have two vectors x and y .

I want to plot them both as coordinates, ex: (x1,y1) ; (x2,y2) (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.

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.

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.

Why this didn't work?

plot(x,y,'o','MarkerFaceColor','b'); axis square; hold on

best

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM