I want to plot current data (direction and magnitude) as vectors in a single plot
31 次查看(过去 30 天)
显示 更早的评论
Hi! I'm trying to plot a timeseries of current data in away that I have seen wind velocity data displayed like in the example attached. I have current direction (dir_adp3_mx) and magnitude (mag_adp3_mx) and my timestamps (MX). Can I use this data to make a plot of current velocity like the plot of wind speeds below? I think I need to use the quiver or feather functions but I am confused on how to make the X axis time in either case. Please help if you have ideas. I attached the data I am working with as data.mat.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/391893/image.png)
0 个评论
回答(1 个)
Mathieu NOE
2020-10-26
hello Heidi
below some code with quiver vs feather display. depneds of your preferences - seem I got better angular rendering with quiver.
also note that I have dispayed only the first 100 samples to get a better picture to show the differences in rendering
I have manually added a baseline to the standard quiver display - so at the end it's very similar to what feather do;
you can of course remove that
hope it helps
Mathieu
load data.mat
% data file content :
% Name Size Bytes Class Attributes
%
% MX 4888x1 39104 double
% dir_adp3_mx 4888x1 39104 double
% mag_adp3_mx 4888x1 39104 double
% quiver(X,Y,U,V) plots velocity vectors as arrows with components (u,v)
% at the points (x,y). The matrices X,Y,U,V must all be the same size
% and contain corresponding position and velocity components (X and Y
% can also be vectors to specify a uniform grid). quiver automatically
% scales the arrows to fit within the grid.
% we need to create the X and Y coordinates of each vector
% NB : current direction (dir_adp3_mx) is in degrees
direction_rad = pi/180*dir_adp3_mx;
Xvec= mag_adp3_mx.*cos(direction_rad);
Yvec= mag_adp3_mx.*sin(direction_rad);
% create x,y points for quiver % quiver(X,Y,U,V) plots velocity vectors
% as arrows with components (u,v) at the points (x,y).
time = MX-MX(1); % so x start at 0 (needed ?)
y = zeros(size(x)); % base line
samples = 100; % to remove if necessary
%
figure(1)
quiver(time(1:samples),y(1:samples),Xvec(1:samples),Yvec(1:samples),'.');
% add central line
hold on
plot(time(1:samples),y(1:samples));
hold off
% quiver(...,LINESPEC) uses the plot linestyle specified for
% the velocity vectors. Any marker in LINESPEC is drawn at the base
% instead of an arrow on the tip. Use a marker of '.' to specify
% no marker at all. See PLOT for other possibilities.
figure(2)
feather(Xvec(1:samples),Yvec(1:samples))
0 个评论
另请参阅
类别
在 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!