Borrar filtros
Borrar filtros

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

4 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

Walter Roberson
Walter Roberson el 26 de Mayo de 2017
  2 comentarios
mattyice
mattyice el 30 de Mayo de 2017
Editada: mattyice el 30 de Mayo de 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 el 30 de Mayo de 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)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Visual Exploration en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by