Remove unwanted vectors from a vector plot
6 次查看(过去 30 天)
显示 更早的评论
I am using this program to sort through vector files and plot the average data using the quiver function. In one of my experiments, there is a wall that the flow runs into, this presents a problem in displaying that data. I want to remove the unwanted data that is caused by the wall, could someone help me modify the code to do so?
function [x,y,u_avg,v_avg,CHC_tot] = piv_averages(prefix,suffix,Nstart,Nfinish,interp)
% This program reads in a series of instantaneous PIV vector fields from
% Insight and averages them. The user has the option of excluding
% interpolated vectors, which have CHC > 1. (interp = 0 means do not
% interpolate, while interp = 1 means interpolate).
% Create file name for each image
c_exit=1.22 %speed of sound
x0=1073 %origin of the jet in pixels
y0=53.8 %origin of the jetin pixels
D=923.71 %diameter of jet exit in pixels
v_shift=0
for i = Nstart:Nfinish
Nstring = int2str(i); % Convert iteration number to a character string
if i < 10
filename_inst = strcat(prefix,'0000',Nstring,suffix);
elseif i < 100
filename_inst = strcat(prefix,'000',Nstring,suffix);
elseif i < 1000
filename_inst = strcat(prefix,'00',Nstring,suffix);
elseif i < 10000
filename_inst = strcat(prefix,'0',Nstring,suffix);
else
filename_inst = strcat(prefix,Nstring,suffix);
end
% Read file name
A_inst = csvread(filename_inst,1,0);
x = A_inst(:,1); % x-position (mm)
y = A_inst(:,2); % y-position (mm)
u = A_inst(:,3); % x-velocity (m/s)
v = A_inst(:,4); % y-velocity (m/s)
chc = A_inst(:,5); % number of good vectors at this location
N = size(x,1); % Length of entire vector array
% Initialize output variables if this is the first file
if i == Nstart
u_tot = zeros(N,1);
v_tot = zeros(N,1);
CHC_tot = zeros(N,1);
end
for j = 1:N
if interp == 0
if chc(j,1) == 1
u_tot(j,1) = u_tot(j,1) + u(j,1);
v_tot(j,1) = v_tot(j,1) + v(j,1);
CHC_tot(j,1) = CHC_tot(j,1) + 1;
end
elseif interp == 1
if chc(j,1) > 0
u_tot(j,1) = u_tot(j,1) + u(j,1);
v_tot(j,1) = v_tot(j,1) + v(j,1);
CHC_tot(j,1) = CHC_tot(j,1) + 1;
end
end
end
end
for j = 1:N
u_avg(j,1) = u_tot(j,1)/CHC_tot(j,1);
v_avg(j,1) = v_tot(j,1)/CHC_tot(j,1);
end
% Set origin to jet exit centerline
x_c = x - x0;
y_c = y - y0;
% Shift by convective velocity
v = v - v_shift;
% Nondimensionalize variables
x_non = x_c/D; % Nondimensionalize using jet diameter
y_non = y_c/D; % Nondimensionalize using jet diameter
u_non = u/c_exit; % Nondimensionalize using sonic speed
v_non = v/c_exit; % Nondimensionalize using sonic speed
% Plot nondimensional vector field
figure(2)
quiver(x_non,y_non,u_non,v_non,5)
xlabel('x/D')
ylabel('H/d')
title('Nondimensional velocity field')
% Plot averaged vector field
figure(1)
quiver(x,y,u_avg,v_avg,5)
xlabel('z (mm)')
ylabel('x (mm)')
title('Dimensional velocity field')
% Output averaged data
output_avg = [x y u_avg v_avg CHC_tot];
dlmwrite('average_vels.dat','xyUVC');
dlmwrite('average_vels.dat',output_avg,'-append');
Here is an example of one of my velocity fields. The vectors along the bottom of the image need to be removed. Thank you in advance!
6 个评论
采纳的回答
Adam Danz
2019-10-16
编辑:Adam Danz
2019-10-16
To eliminate any quiver arrow that start below a given threshold along the y-axis,
% 1) Choose a threshold
yThreshold = 100; %accept all vectors that start at or above y = yThreshold;
% 2) identify all quiver arrows that meet the criteria
acceptIdx = data.y >= yThreshold;
% 3) plot the quiver arrows, but only the ones accepted
figure()
quiver(x(acceptIdx), y(acceptIdx), U(acceptIdx), V(acceptIdx), 5)
% add reference line at threshold if you'd like
yline(yThreshold);
Alternatively, you can identify the yThreshold as some distance from the smallest y-value. In this example below, the yThreshold is set to the minimum y-value plus 0.1% of the range of y-data.
yThreshold = min(data.y) + range(data.y)*.001
0 个评论
更多回答(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!