1
$\begingroup$

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?

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

$\endgroup$
1
$\begingroup$
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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.