# Any suggestions to measure the distance between two lines or regions (the dip represents low intensity)

1 Ansicht (letzte 30 Tage)
BA am 30 Jul. 2022
Beantwortet: Varun am 1 Sep. 2023
Here I plotted the centre of gravity between two regions, then I would like to measure the distance between these two line using gridline or region of interest, maybe , any suggestions?
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Varun am 1 Sep. 2023
Hello!
As per my understanding, you want to measure the distance between two lines that have been plotted in the figure. There are multiple ways to go about it:
1. Using the “drawline function: The “drawline” function lets you create a customizable region-of-interest. So, in the figure window, you can measure the distance between the lines by connecting the lines using “drawline”, by placing one end-point on each line. The line’s Position properties can be used to get the coordinates of its endpoints, using which the Euclidean distance can be calculated. Example:
h1 = drawline();
distance=sqrt((h1.Position(1,1)-h1.Position(2,1))^2 + (h1.Position(1,2)-h1.Position(2,2))^2);
2. Using the “ginput” function: The “ginput” function lets you identify axes coordinates in a Figure window. So, “ginput” can be used to pick two points, one lying on each line. Using the coordinates of these points, the Euclidean distance can be calculated. Example:
disp('Select a point on Line 1:');
[x1_point, y1_point] = ginput(1);
scatter(x1_point, y1_point)
% Select points on Line 2
disp('Select a point on Line 2:');
[x2_point, y2_point] = ginput(1);
scatter(x2_point, y2_point);
% Calculate the distance between the selected points
distance = sqrt((x2_point - x1_point^2 + (y2_point- y1_point)^2);
Hope this helps!
Thanks,
Varun
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!