Extract All Columns from Matrix
n.black
I have a matrix where every column is spectroscopic data. I would like to extract every column as a wave to ultimately then do batch curve fitting. Unfortunately I can't load all the data as individual waves as the txt file needs to be transposed first and bits and pieces removed. Unless there are ways to easily plot multiple columns from the matrix (or rows from an IGOR table)
I found this bit or code where you specify which points to extract.
Duplicate/O/R=[2,*][1,*] wave0, Spectra
Where [x0,xn][y0,yn] is [row][column]
Is there a way I can make a "columnlist" similar to the "wavelist" function? I was thinking to write a loop to extract a new set of waves. Is there an easy way to do this?
Thanks,
N
You can display a subset of a wave in a graph. These commands:
Display mywave[1][]
Display mywave[][1]
will make a graph of row 1 of the matrix wave mywave, then a graph of column 1 of mywave. To do this with the New Graph dialog:
1) If you have a button that reads "More Choices" click it so that you have a more complicated dialog with a trace list at the bottom and an Add button.
2) Select your Y wave and, optionally, X wave and click the Add button.
3) In the trace list, edit the subrange info right in the list.
You can also use wave subranges with curve fitting. And the Batch Curve Fit package supports batch fits to all the columns of a matrix. If you need rows, I guess transpose first.
Now, if you still want to make a bunch of 1D waves, here is a function to do it:
Wave w
Variable doRows
String basename = NameOfWave(w)
Variable i
if (doRows)
MatrixTranspose w
endif
Variable nCols = DimSize(w, 1)
for (i = 0; i < nCols; i += 1)
String wname = basename + num2str(i)
Duplicate/O/R=[][i] w, $wname
endfor
if (doRows)
MatrixTranspose w
endif
end
Note that since it adds a number to the end of the new wave names, the original wave should have a name shorter than the maximum 31 characters. You could add a string input to set the basename of the waves; I leave that as an excercise... Also, there is no sanity checking. It may behave oddly if the input wave isn't a 2D matrix wave.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
August 11, 2015 at 10:03 am - Permalink
That really helped me out. It's good to know both methods after all!
Best,
N
August 13, 2015 at 04:04 am - Permalink