필터 지우기
필터 지우기

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