# Taking a diagonal cut through a matrix

Lets say I have a gaussian data matrix, e.g.

x=GaussianMatrix


I would like to take a cut through this matrix at a 45 degree angle to get its intensity profile, like this: rather than a straight line cut in the x or y coordinates. Is there a way to do this?

• Diagonal[x] to get the main diagonal, or Diagonal[x, k] to get elements on the $k$-th diagonal. Aug 25 at 10:10
• Thank you! What if I want to take the cut at a different angle? not necessarily at the diagonal? Aug 25 at 10:39
• Is there any particular reason why you are using a matrix and not a two dimensional Gaussian PDF? Anyhow, to get a different angle, you could use the Bresenham algorithm. There is at least one solution here on SE. Or use something like: Binarize[Rasterize[Graphics[Line[{{0, 0}, {2, 3}}]], RasterSize -> 40]]. Aug 25 at 10:42

x = GaussianMatrix;


Construct an interpolation:

j = ListInterpolation[x, {{-1, 1}, {-1, 1}}, InterpolationOrder -> 3];


Plot at arbitrary angle:

With[{α = 0.3},
Plot[j[t*Cos[α], t*Sin[α]], {t, -1, 1}]] x = GaussianMatrix;
MatrixPlot[x]

Manipulate[
ListLinePlot[Diagonal[x, i], PlotRange -> {{0, 40}, {0, 0.002}}],
{i, -Dimensions[x][], Dimensions[x][], 1}
] 