Measuring distance in 2D plot
73 ビュー (過去 30 日間)
古いコメントを表示
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);
0 件のコメント
採用された回答
Scott MacKenzie
2021 年 6 月 22 日
編集済み: Scott MacKenzie
2021 年 6 月 22 日
Just adding this to the end of your code achieves what you are after (I think). The x-length of the line easy enough to calculate, or am I missing something?
% test coordinates for line, as per photo in question
xx = [-3.5 -1.75];
yy = [-17 -19];
% draw line
line(xx, yy, 'linewidth', 5);
% compute x-length
xlength = abs(min(xx)-max(xx));
% display x-length
text(-3, -16, sprintf('x-length=%.2f', xlength), 'backgroundcolor', 'w');
3 件のコメント
Scott MacKenzie
2021 年 6 月 22 日
編集済み: Scott MacKenzie
2021 年 6 月 22 日
Hmm, OK, I get it. You want to interact with the graph, not draw lines in the graph. Not sure if this sufficient, but If you use the brush tool, you can interactively get the x-coordinates between lines, and therein get the x length:
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Vector Fields についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!