How do I change the direction of a quiver vector at the same time change the sign of its magnitude ?
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi! I am plotting a velocity field with the help of quiver. I want to reverse the direction of some of the vectors, but at the same time, want to change the sign of its magnitude. For example, if the vector is pointing in negative Y direction with a magnitude of 10 units, I want it to point in positive Y direction with the magnitude of -10 units so that the meaning of the vector remains the same. How do I do this in MATLAB ?
0 Kommentare
Antworten (2)
KSSV
am 9 Nov. 2016
You can change the direction of y by using quiver(x,y,u,-v) instead of quiver(x,y,u,v).
Coming about magnitude, it is given by sqrt(u^2+v^2). You have no control on it's sign. It will be always positive.
0 Kommentare
SOURAV KUMAR
am 29 Mär. 2021
You can use quiver(x0,y0,-v1,-v2) instead of quiver(x0,y0,v1,v2) to reverse a vector
For Example, consider the following code:
clc
clear all
close all
x0=1;
y0=2;
v1=-1;
v2=1;
quiver(x0,y0,v1,v2,'r')
hold on
quiver(x0,y0,-v1,-v2,'g')
legend('Original Vector','Reverse Vector')
hold on
plot(x0,y0,'k*')
Output:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/566016/image.jpeg)
Note: It will be incorrect to use the term magnitude as magnitude of a vector is always positive;
However you can say to change the sign of the vector,
i.e., If original vector is
, then desired vector is ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/566026/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/566021/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/566026/image.png)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Vector Fields finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!