Filter löschen
Filter löschen

How do you get an arbitrary 1 dimensional line scan from a 2D Matrix

4 Ansichten (letzte 30 Tage)
Hello,
say I had a NxN Matrix
Is there any easy way to plot a line scan from any arbitrary points (x1,y1) to (x2,y2)?
Example, attached is a 256x256 variable tdelt
I want a line profile of the data between the points (81,96) and (188,40)
Not sure How I can do this
Thanks!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 26 Mai 2017
  2 Kommentare
mattyice
mattyice am 30 Mai 2017
Bearbeitet: mattyice am 30 Mai 2017
Ahh ok, so, if I want the line from (81,96) and (188,40) in the 2D variable tdelt,
I set
x=[81 188]
y=[96 40]
improfile(tdelt,x,y)
This will plot the values of the tdelt along this line against distance in pixels.
How do I change the x-axis if I definine the x and y axes of the values given in tdelt as length=linspace(0,2150,128). As in these values are mapped across a 2.15um X 2.15um square area. I want the x-axis reflective of that length scale.
Thanks
Walter Roberson
Walter Roberson am 30 Mai 2017
[r, c] = size(tdelt);
row_coords = linspace(0, 2150, r+1);
row_coords(end) = [];
col_coords = linspace(0, 2150, c+1);
col_coords(end) = [];
%now coords represent the "left" or "top" edge of each pixel
xidx =[81 188]; %in terms of indices
yidx =[96 40]; %in terms of indices
x = col_coords(xidx);
y = row_coords(yidx);
N = 1 + max( max(xidx) - min(xidx), max(yidx) - min(yidx) );
x_to_interp = linspace(x(1), x(2), N);
y_to_interp = linspace(y(1), y(2), N);
[X, Y] = meshgrid(col_coords, row_coords);
profile = interp2(X, Y, tdelt, x_to_interp, y_to_interp);
plot(x_to_interp, profile)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Visual Exploration 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!

Translated by