Draw a rectangle in a plot based upon ZERO values as the boundaries

8 ビュー (過去 30 日間)
Addison Collins
Addison Collins 2021 年 6 月 21 日
編集済み: Addison Collins 2021 年 6 月 22 日
Hello,
I have some PIV data that I have plotted (see images). There is a large rectangle of 0 values that represents a probe that I masked during data collection. I'd like to plot some rectangles that represent the 1mm thick walls of the probe so I can visualize the streamlines entering the probe. The graph provides x-distance in mm, for reference. Below I attached a photo with the graph I am trying to get to (used MS Paint to draw walls). The data file is attached as a .txt document.
EDIT: I suppose I should add that the probe has an inner (hole) diameter of 2 mm and an outer diameter of 4mm (1mm thick walls). The region masked (0 values) is slighlty larger than the diameter of the probe.
The following are 540 x 640 matrixes (rownum x colnum):
Xq - X-location (mm)
Yq - Y-location (mm)
Uq - X-velocity (m/s)
Vq - Y-velocity (m/s)
EDIT:
I have since manually plotted the probe geometry, but it would be nice if I could find a way to approixmate the location of the wall by seeing the 0 values of the probe. I modified the code below to reflect the updates.
Main:
% Addison Collins
% PIV streamlines code
clc;clear;close all
file = dir('*.txt');
filename = file.name;
data = readmatrix(filename);
% Min and max of the data x and y
kx = 0; % mm - Shifting factor
ky = 0;
spanX = [min(data(:,1))+kx max(data(:,1 ))+kx];
spanY = [min(data(:,2))+ky max(data(:,2 ))+ky];
% Generate equally spaced x and y arrays
Xq = linspace(spanX(1),spanX(2),640);
Yq = linspace(spanY(1),spanY(2),540);
% Create the combination of xq and yq
[Xq, Yq] = meshgrid(Xq,Yq );
% Interp the data if the x and y data in the file is not in a grid
Uq = griddata(data(:,1),data(:,2),data(:,3),Xq,Yq);
Vq = griddata(data(:,1),data(:,2),data(:,4),Xq,Yq);
xtip = -4.5;%-1.5; % Bottom left vertice of left probe wall
ytip = -7.703; % Bottom left vertice of left probe wall
height = 12.7; % mm
width = 1; % mm
gap = 3; % mm - Distance between probe walls (left end of the walls)
%% Plot vectors, probe walls, and streamlines
figure()
quiver(Xq,Yq,Uq,Vq) % Plot vectors
title(['Averaged Velocities and Streamtubes'])
% Plot probe walls
rectangle('Position',[xtip,ytip,width,height],'FaceColor','k')
rectangle('Position',[xtip+gap,ytip,width,height],'FaceColor','k')
% 45deg chamfer (plot tiangles)
b = 0.4;
x2 = [xtip+b; xtip+width; xtip+width];
y2 = [ytip; ytip; ytip+1];
t1 = patch(x2,y2,'white');
t1.EdgeColor = 'white';
x2 = [xtip+gap+width-b; xtip+gap; xtip+gap];
y2 = [ytip; ytip; ytip+1];
t2 = patch(x2,y2,'white');
t2.EdgeColor = 'white';
% Plot streamlines
xlabel('x (mm)')
ylabel('y (mm)')
startx = -10:0.3:6 ;
starty = -20*ones(size(startx ));
hgridinterp = streamline(Xq,Yq,Uq,Vq,startx,starty );
set(hgridinterp,'color','red','linewidth',4);

回答 (0 件)

カテゴリ

Help Center および File ExchangeVector Fields についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by