How do I use Quiver with X, Y, radians and vector length?

조회 수: 30 (최근 30일)
Right Grievous
Right Grievous 2015년 5월 21일
댓글: Chad Greene 2015년 5월 22일
Hi everybody,
I would really like to use a quiver plot to display my data, however, I can't seem to get it to work properly, the plot never looks like it should and any changes I make just seem to result in random results.
I have two matrices, one contains heading direction in radians, the other contains the strength of this heading/vector length or intensity.
So from these I have X, Y, direction (in radians) and something that could be considered analogous to velocity (actually Rayleigh vector lengths).
I know I should be able to plot this data using Quiver but I don't seem to understand how the inputs work. I have looked over the help and doc information but they keep using examples generated from sin or cos applied to a matrix, which really doesn't help me understand the inputs any better.
Any help would be massively appreciated.
Rod.
Sample Data:
if true
figure
[X,Y] = meshgrid(1:1:10);
heading = deg2rad(randi([-180 180],10,10));
r = randi([0 10],10,10);
quiver(X,Y,heading,r)
end

채택된 답변

Chad Greene
Chad Greene 2015년 5월 21일
If you have the locations of points X and Y, all you have to do is convert your direction/magnitude information to cartesian coordinates. For direction theta and magnitude rho,
[u,v] = pol2cart(theta,rho);
then
quiver(X,Y,u,v)
should do the trick.
  댓글 수: 2
Right Grievous
Right Grievous 2015년 5월 22일
Absolutely fantastic - this is the step I was missing.
Another tip for anyone reading this, I wanted to compare my quiver plot to a plot produced by imagesc - imagesc automatically flips imaged matrices (because 0,0 is top left I think instead of bottom right) but you can use "set(gca,'YDir','normal')" to correct this and then they should both line up.
Thanks a bunch!
Chad Greene
Chad Greene 2015년 5월 22일
Alternatively, you can use axis xy to flip the y direction back from imagesc's default axis ij.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by