How to track the vector magnitude in quiver plot?

Hello Matlabers,
When I use quiver to get a vector plot, I find that I couldn't use data cursor to track the value of the clicked point. Is it possible to do this by data cursor? If it's impossible, how can I do to get the vector magnitude when I click the arrow in the plot?
Thanks in advance.
Xiaoliang

 Accepted Answer

If you use quiver(x,y,u,v), the data cursor mode will show the (x,y,u,v) value for every point that is plotted. I guess you want the value of sqrt(u^2+v^2). That is not available in the plot. If you want to have that, you need to plot it somewhere in the figure.
use quiver(x,y,u,v,scale) to adjust the length of the arrow line.
Follow Doug's video tutorial to create a customized data cursor function. http://blogs.mathworks.com/videos/2011/02/25/creating-a-custom-data-cursor/

2 Comments

You could use a custom datacursormode callback to display sqrt(u^2+v^2) as part of the output.
Good point, Walter! Now I recall one of Doug's video.

Sign in to comment.

More Answers (2)

To Fangjun,
Thanks very much. Actually, before I saw your answer, I had thought it was impossible to show (x,y,u,v) in quiver plot. Because every time I tried, it gave out an error, or a result like this [x: y : u: v:], that is, there was no value for them. After I read your reply, I went back to the help doc on quiver, and I used the example in it to test it. Finally, I located my problem. It seems that if you use quiver(u,v), you can get a correct vector plot sometimes, but you cannot use data cursor; however if you use quiver(x,y,u,v), then there is no problem at all!
And I have a another question. When doing data cursor, if I right click, select 'Edit text update function', then I save it as a .m file without any modification. After that, I do data cursor again, but this time I right click, and select test update function saved. Now, in the datatip, I can only see the value X and Y! Why??
Thanks in advance.
Xiaoliang

Categories

Community Treasure Hunt

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

Start Hunting!