How do you get an arbitrary 1 dimensional line scan from a 2D Matrix
3 views (last 30 days)
Show older comments
mattyice
on 26 May 2017
Commented: Walter Roberson
on 30 May 2017
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!
0 Comments
Accepted Answer
Walter Roberson
on 26 May 2017
2 Comments
Walter Roberson
on 30 May 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)
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!