1

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

x=GaussianMatrix[20]

I would like to take a cut through this matrix at a 45 degree angle to get its intensity profile, like this:

enter image description here

rather than a straight line cut in the x or y coordinates. Is there a way to do this?

  • 4
    Diagonal[x] to get the main diagonal, or Diagonal[x, k] to get elements on the $k$-th diagonal. – Domen Aug 25 '21 at 10:10
  • Thank you! What if I want to take the cut at a different angle? not necessarily at the diagonal? – aCuriousPhysicist Aug 25 '21 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]]. – Domen Aug 25 '21 at 10:42

2 Answers2

3
x = GaussianMatrix[20];

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}]]

enter image description here

Roman
  • 47,322
  • 2
  • 55
  • 121
1
x = GaussianMatrix[20];
MatrixPlot[x]

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

enter image description here

Syed
  • 52,495
  • 4
  • 30
  • 85