I'm trying to write some automated data analysis code for my research group, but I've run into a snag with Mathematica which I just can't seem to iron out.

We generate data of the form:


Where, if the matrix is called data, data[[1,2;;]] is a selection of Voltage values, and data[[2;;,1]] is a selection of Wavelength values. data[[2;;,2;;]] gives Intensity.

I know that the wavelength values are defined by the instrument, but the voltage sweep is user-defined, so its dimensions are not fixed.

In MatLab, I would do the following:

hold on
for i=2:a(2)

and this would generate my desired result of a single plot, with multiple traces each corresponding to a given measurement.

In Mathematica, I've tried several methods each without success. Because ListLinePlot expects a list of form {x1,y1},{x2,y2},... I figure there must be some obvious way to treat the data to achieve the desired result, but I haven't found it. If there were an equivalent hold on function in Mathematica, I would do the following:


But as far as I can find, such a function doesn't exist.

Is there some slick way I can do this that I'm missing?

Thanks for reading


If I understand what you mean, then the following might work (note that I have added an extra line of fake data):

data = {
   {  0, -2, -1,  0,  1,  2},
   {380,  1,  2,  3,  4,  5},
   {384,  6,  7,  8,  9, 10},
   {386, 11, 12, 13, 14, 15}};

  Transpose@data[[2 ;;, 2 ;;]],
  DataRange -> MinMax@data[[2 ;;, 1]],
  PlotLabels -> data[[1, 2 ;;]]


Here DataRangeis the key element to the solution: it specifies what range of actual coordinates the data should be assumed to occupy, so you do not need to provide a list of ${x, y}$ coordinate pairs, but simply a list of $y$ coordinates, and then the abscissae are reconstructed for you.

This also makes no assumptions on the size of the data set; it simply expects the first column to contain wavelengths to set the DataRange; the first row is used as labels for each plot line.

| improve this answer | |
  • $\begingroup$ Thanks, this is basically what I was looking for! $\endgroup$ – BesselFunct Nov 25 '19 at 23:13

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.