Remove unwanted vectors from a vector plot
Show older comments
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 Comments
It sounds to me that the problem isn't removing the quiver arrows from the plot. The problem is identifying those data points and not plotting them in the first place.
After you read in the data, determine which data points are affected by the wall and replace their values with NaNs.
As to how you'll detect those data points, that depends on how the data are generated and what each variable represents etc. For example, do all data points affected by the wall have a starting coordinate at y=50 (or whatever the bottom edges is of the image)?
Monique Embury
on 26 Sep 2019
(x_non, y_non) are the starting coordinates of each vector. If the vectors that you want to remove all start at the bottom of the image, you just need to 1) find the minimum value in y_non and 2) detect which indices of y_non are within some small window around that minimum value. Once you have a list of indices you just need to 3) replace those values with NaN prior to plotting.
Monique Embury
on 30 Sep 2019
Monique Embury
on 16 Oct 2019
Adam Danz
on 16 Oct 2019
I didn't suggest a loop. It just requires a few steps (see my answer below).
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!