understanding quiver and plotting arrows with direction and speed
조회 수: 18 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Voss
2024년 3월 25일
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
Voss
2024년 3월 25일
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; ...
]
% 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)
% 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')
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!