Using quiver to vary magnitudes of the vector
4 次查看(过去 30 天)
显示 更早的评论
Hi there,
I need to change the magnitude of each point on a quiver plot. Here is the code;
py= 49.35/Dmm;
px = (0.3125*Dmm)/Dmm;
g = streamline(X,Y,vx,vy,px,py); %plotting the upper line
x = g.XData;
y = g.YData;
xx = x(ind);
yy = y(ind);
dx = gradient(xx)
dy = gradient(yy)
[dx,dy] = magvec(9, dx ,dy) %Custom function to change magnitude
p = plot(xx,yy,'r') %stream line
f = quiver(xx,yy,-dy,dx,'g') % plotting the components
the -dy, dx is to plot the vectors outward to the line. i'm not sure how quiver works, but the problem is that the result plotted isn't tangent to the stream line after i pass the dx and dy values through the magvec function, but is tangent and works correctly when i dont pass it through the magvec function. The error could be in magvec, and there are some redundancies in the function (could have multiplied dx by mag directly), but otherwise nothing (that i can see) should cause an error.
i'd really appreciate any help here.
this figure shows the plot after using magnitude as 2 for the upper contour, which should ideally be larger than the lower one.
the function that i used to change the magnitude:-
function [x,y] = magvec(mag, dx ,dy)
oldmag = (dx.^2+dy.^2).^0.5;
newmag = oldmag.*mag;
ratio = newmag/oldmag;
x = dx.*ratio;
y = dy.*ratio;
end
1 个评论
darova
2020-5-17
Here is the problem
But there is no need in such operations. YOu are calculating ratio
ratio = oldmag.*mag./oldmag;
ratio = mag;
回答(1 个)
darova
2020-5-16
- but the problem is that the result plotted isn't tangent to the stream
Why did you change dy and dx order here?
f = quiver(xx,yy,-dy,dx,'g') % plotting the components
3 个评论
darova
2020-5-16
Maybe problem is in quiver scaling
what about this
f = quiver(xx,yy,-dy,dx,'g',4) % plotting the components
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Vector Fields 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!