Plotting 3D Vector Field
조회 수: 94 (최근 30일)
이전 댓글 표시
I am attempting to plot the following vector field using the quiver3 function;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284079/image.png)
with the following code;
[y] = meshgrid(linspace(0,2,100));
% We now define our 3 vector−field functions
P = y.^2-2*y;
Q = 0*y;
R = 0*y;
% Plot the 3D vector field with quiver3
figure(2)
quiver3(y,P,Q,R)
ylim([0,2])
xlabel('x')
ylabel('y')
zlabel('z')
However, the resulting plot is not very informative as all the arrows and their places seem to be scaled strangely.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284080/image.png)
Would anyone be able to help make a neater looking plot with more arrows showing the different directions? Thanks
댓글 수: 0
답변 (1개)
Ameer Hamza
2020년 4월 13일
This vector field has all vectors pointing toward x-axis, and the length of vectors is only a function of y. So the field will appear very uniform. You also need to consider the x and y grid to plot it properly. Please try the following code.
[x,y,z] = meshgrid(linspace(0,0.5,10), linspace(0,2,100), linspace(0,0.5,10));
% We now define our 3 vector−field functions
P = y.^2-2*y;
Q = 0*y;
R = 0*y;
% Plot the 3D vector field with quiver3
figure(2)
quiver3(x,y,z,P,Q,R)
grid on
ylim([0,2])
xlabel('x')
ylabel('y')
zlabel('z')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!