Changing the arrow colors on a quiver plot to match velocity speeds
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I have run several simulations and output velocity vector fields. I Have also run experiemnts and processed quiver plots. I was hoping to get MATLAB to produce similar images as my simulations.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/274106/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/274107/image.jpeg)
Here is my code:
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=2.776; %speed of sound
x0=1040; %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)+162; % x-position (mm)
y = A_inst(:,2)-198.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
% define orifice opening in pixels
orificepl=linspace(0, x0-(D/2));
orificepr=linspace(x0+(D/2), 2016);
yorifice=2016*ones(size(orificepl));
% define orifice opening in mm
orificeml=linspace(0, (x0-(D/2))/48.11);
orificemr=linspace((x0+(D/2))/48.11, 2016/48.11);
% define orifice opening non-dimensional
orificendl=(orificepl-x0)/D;
orificendr=(orificepr-x0)/D;
% 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_avg/c_exit; % Nondimensionalize using sonic speed
v_non = v_avg/c_exit; % Nondimensionalize using sonic speed
x_non_d=downsample(x_non,15);
y_non_d=downsample(y_non,15);
u_non_d=downsample(u_non,15);
v_non_d=downsample(v_non,15);
% Plot nondimensional vector field
figure(2)
qp=quiver(x_non_d,y_non_d,u_non_d,v_non_d,3)
line(orificendl,yorifice/1008, 'linewidth', 4, 'color', 'k')
line(orificendr,yorifice/1008, 'linewidth', 4, 'color', 'k')
axis([-1 1 0 2])
xticks([-1 0 1])
yticks([0 1 2])
colormap('jet')
colorbar;
set(gca,'YtickLabel',2:-1:0)
set(gca,'XAxisLocation','top','YAxisLocation','left');
xlabel('z/D')
ylabel('x/D')
% title('Nondimensional velocity field')
set(findall(gcf,'-property','FontSize'),'FontSize',16)
If anyone could help me I would greatly appreciate it. Than kyou in advance!
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Red 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!