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

4 次查看(过去 30 天)
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!

采纳的回答

Walter Roberson
Walter Roberson 2017-5-26
  2 个评论
mattyice
mattyice 2017-5-30
编辑:mattyice 2017-5-30
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 2017-5-30
[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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by