Measuring distance in 2D plot
Show older comments
Hello everyone,
I am attempting to measure the horizontal length between two almost parallel streamlines. I would like to simply draw a line on the plot and have it display the length in the X-direction (not the length of the line itself). Is this an easy thing to do? I could not find it in the plot tools. I have attached the code and the mat file used in this.
Edit: In the photo below, I show what I have been attempting to do.
% 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, 1)%, 'LineWidth',2) % Plot vectors
% quiver(Xq,Yq,Uq,Vq)
title(['Averaged Velocities and Streamlines'])
% Plot probe walls
rectangle('Position',[xtip,ytip,width,height],'FaceColor','k')
rectangle('Position',[xtip+gap,ytip,width,height],'FaceColor','k')
% Plot streamlines
xlabel('x (mm)')
ylabel('y (mm)')
startx = -10:0.4:6 ;
starty = -20*ones(size(startx ));
hgridinterp = streamline(Xq,Yq,Uq,Vq,startx,starty );
set(hgridinterp,'color','red','linewidth',3);

Accepted Answer
More Answers (0)
Categories
Find more on Vector Fields in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
