understanding quiver and plotting arrows with direction and speed

20 views (last 30 days)
Im pretty sure I am trying to make a map using quiver. I have AUV data from a vehicle that collected current information. The data collected is lat, long, depth, current speed, and current direction, so 5 total variables. The current direction is just a degree reading, for example water passed by the vehicle at 255° relative to the front of the vehicle. What I want to do is plot the direction and intensity of water for the duration of the survey. The code I wrote is below, Im trying to use quiver for this but the result is all the vectors being the same length and in the same direction. Looking at the data I can see that that is not the case, water direction changes as well as speed of the water. Am I not understanding something about quiver, or am I plotting the data incorrectly? Any advice would be appreciated.
P = 'C:/Users/keith/OneDrive/Desktop/Single Beam Bathy/SN06222';
Q = 'C:/Users/keith/OneDrive/Desktop/Single Beam Bathy/SN06222/Corrected CSV';
S = dir(fullfile(P,'*.csv'));
S = natsortfiles(S);
N = numel(S);
C = cell(N,1);
C1 = cell(N,1);
for k= 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
O = readmatrix(F);
[M, ~, ~] = rmoutliers(O,1);
lat = M(:,1);
lon = M(:,2);
dep = M(:,4);
alt = M(:,8);
currentS = M(:,24);
currentD = M(:,25);
Dep = -1*(alt+dep);
depS = smoothdata(Dep,'movmedian',500);
end
X = lon;
Y = lat;
U = currentD;
V = currentS;
quiver(X,Y,U,V,)
Heres an example of the output.

Accepted Answer

Voss
Voss on 25 Mar 2024
U and V are supposed to be the X- and Y-components of the quiver arrows, but you are using direction and speed directly for U and V.
You'll need to calculate the components, e.g.
U = currentS.*cosd(currentD);
V = currentS.*sind(currentD);
  5 Comments
Voss
Voss on 25 Mar 2024
Here's an example of using interp1 to add a new data point in between each two consecutive existing points. This is done in one interp1 call which adds new rows to M to form M_new, and plotting from that:
% data
M = [ ...
45 -90 10 255; ...
46 -90.5 15 270; ...
46 -92 12 240; ...
45 -93 13 215; ...
]
M = 4x4
45.0000 -90.0000 10.0000 255.0000 46.0000 -90.5000 15.0000 270.0000 46.0000 -92.0000 12.0000 240.0000 45.0000 -93.0000 13.0000 215.0000
% plotted variables setup
lat = M(:,1);
lon = M(:,2);
currentS = M(:,3);
currentD = M(:,4);
% plot
figure()
X = lon;
Y = lat;
U = currentS.*cosd(currentD);
V = currentS.*sind(currentD);
quiver(X,Y,U,V)
axis equal
title('original')
% interpolate data
N = size(M,1);
t = 1:N;
t_new = linspace(1,N,2*N-1);
M_new = interp1(t,M,t_new)
M_new = 7x4
45.0000 -90.0000 10.0000 255.0000 45.5000 -90.2500 12.5000 262.5000 46.0000 -90.5000 15.0000 270.0000 46.0000 -91.2500 13.5000 255.0000 46.0000 -92.0000 12.0000 240.0000 45.5000 -92.5000 12.5000 227.5000 45.0000 -93.0000 13.0000 215.0000
% plotted variables setup
lat = M_new(:,1);
lon = M_new(:,2);
currentS = M_new(:,3);
currentD = M_new(:,4);
% plot
X = lon;
Y = lat;
U = currentS.*cosd(currentD);
V = currentS.*sind(currentD);
figure()
quiver(X,Y,U,V)
axis equal
title('interpolated')

Sign in to comment.

More Answers (0)

Categories

Find more on Vector Fields in Help Center and File Exchange

Tags

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!