![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/293605/image.png)
Using quiver to vary magnitudes of the vector
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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. ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/293332/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/293332/image.png)
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 commentaire
darova
le 17 Mai 2020
Here is the problem
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/293605/image.png)
But there is no need in such operations. YOu are calculating ratio
ratio = oldmag.*mag./oldmag;
ratio = mag;
Réponses (1)
darova
le 16 Mai 2020
- 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 commentaires
darova
le 16 Mai 2020
Maybe problem is in quiver scaling
what about this
f = quiver(xx,yy,-dy,dx,'g',4) % plotting the components
Voir également
Catégories
En savoir plus sur Vector Fields dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!