MATLAB Answers

Remove unwanted vectors from a vector plot

28 views (last 30 days)
Monique Embury
Monique Embury on 26 Sep 2019
Edited: Adam Danz on 16 Oct 2019
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
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);
filename_inst = strcat(prefix,Nstring,suffix);
% 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);
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;
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;
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);
% 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
title('Nondimensional velocity field')
% Plot averaged vector field
xlabel('z (mm)')
ylabel('x (mm)')
title('Dimensional velocity field')
% Output averaged data
output_avg = [x y u_avg v_avg CHC_tot];
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!


Show 3 older comments
Monique Embury
Monique Embury on 30 Sep 2019
Hi Adam,
I understand this is what I need to do, thank you. I am having issues implimenting it. Can you help with the code?
Monique Embury
Monique Embury on 16 Oct 2019
Do you think you could help? I think I know how to hard code this information, but could you help me create a loop like you suggested?
Adam Danz
Adam Danz on 16 Oct 2019
I didn't suggest a loop. It just requires a few steps (see my answer below).

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 16 Oct 2019
Edited: Adam Danz on 16 Oct 2019
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
quiver(x(acceptIdx), y(acceptIdx), U(acceptIdx), V(acceptIdx), 5)
% add reference line at threshold if you'd like
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


Sign in to comment.

More Answers (0)

Translated by