Extracting a 1D vector from a 3D wave

Hello,

I've been handling spectral images, which are quite naturally stored in 3D arrays where row = abscissa column = ordinate, and layer = wavelength. I switched to Igor to take advantage of its advanced peak fitting capabilities, but a simple operation eludes me: I can't extract the spectrum at a given [row][column]. This is the syntax I've tried:

Make/D/N=(128,320,400) spim=p+q+r //3D wave storing spectral image
Make/D/N=400 spec //1D wave to contain spectrum

spec = spim[115][53][r] //extract spectrum at row=115, column=53


I expect this snippet to give a vector that contains all integers from 168 to 567. But it doesn't work. Spec is a 1D vector containing only 168.

 Display spim[115][53][r] works fine though, which only adds to my confusion...

The underlying idea is to iteratively pass each spectrum of the spectral image to MP2AutoMPFit() for peak identification and fitting.

Any suggestions?
Ok I think I've (finally) got it. In a command such as  Display , r is the the layer of the wave being passed to the copmmand

In a wave assignment, r would refer to the (inexistent) layers dimension of the left-hand side wave in the assignment.

Thus, the correct wave assignment would be:

Make/D/N=(128,320,400) spim=p+q+r //3D wave storing spectral image
Make/D/N=400 spec //1D wave to contain spectrum
 
spec = spim[115][53][p] //extract spectrum at row=115, column=53


And that worked correctly.

Sorry for the decidedly pointless post!
You've figured out one way to do this, but the following options are faster and may or may not be simpler to you:

  • ImageTransform with the getBeam keyword

  • MatrixOP with the beam() function

Thanks! I did not know about MatrixOP. This opens up a whole new realm of possibilities for me!

Here's a question related to using MatrixOP with 3D waves:

I want to sum the columns(rows/beams) using sumColumns(Rows/Beams)

This always returns a 3D wave of size nRows x 1 x nBeams (1 x nColumns x nBeams / nRows x nColumns x 1). I'd like to get rid of the singleton dimension. I tried playing around with  Redimension , but have had no luck yet.

Any suggestions?



I think you need a two-step process: Redimension to a 1-D wave with the same number of points, then Redimension to a 2D wave with the same number of points, but with appropriate rows and columns.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Yes that's what I eventually figured out reading the Manual topic on Multidimensional Waves

Thought there might be some equivalent to MATLAB's squeeze function.

Thanks for the reply nonetheless!