copy and paste values from tables to a new table
daviddoji
I have different tables named as table0, table1, ... with a lot of columns each.
I need to copy values of two columns (but only from a single line) from those tables and to paste these two values into a different table. Of course, I can do it by hand, but I'm wondering if there is a way to do it writing a small macro (maybe a for loop) that I can use in the future.
Thanks a lot.
September 15, 2014 at 05:59 am - Permalink
Sorry for that. Maybe I was not clear enough. Attached you'll find the experiment. In principle, the waves are into different folders, but I can put them into the root folder, no problem for that.
I have different 1D waves organized in different tables (table0, ..., table6). In each of these tables, I need to pick up some values (for example, point0 of the waves 'Ln_RateConv_time' and 'Inv_Temp' from table0, table1, ..., table6) and to add them to two new created waves in a new table, table6 in my example ('Conv_0p1' and 'InvTemp_conv_0p1' in table6).
After that, I need to pick up point1 of the waves 'Ln_RateConv_time' and 'Inv_Temp' from table0, table1, ..., table6 and add them to two new created waves table6, and so on.
Thanks a lot!
September 15, 2014 at 06:18 am - Permalink
If you have not already done it, I highly recommend doing the first half of the Igor guided tour which explains this idea as well as many other important Igor concepts. Choose Help->Getting Started.
Here is a function that accomplishes the specific task that you set out:
Wave Ln_RateConv_time, Inv_Temp // Input waves in current data folder
Wave Conv_0p1, InvTemp_conv_0p1 // Output waves in current data folder
Variable first = Ln_RateConv_time[0]
Variable second = Inv_Temp[0]
Variable numPoints = numpnts(Conv_0p1)
Conv_0p1[numPoints] = {first} // Append data value
numPoints = numpnts(InvTemp_conv_0p1)
InvTemp_conv_0p1[second] = {first} // Append data value
End
That function has very limited utility because it is hard-coded to work with specific waves. Here is a more general function that you can use as a building block to work with any waves:
Wave source // The source wave
Variable sourcePoint // Number of the source point to append to dest
Wave dest // The destination wave
Variable value = source[sourcePoint]
Variable numPoints = numpnts(dest)
dest[numPoints] = {value}
End
Here is an example:
Make/O joe = {4,5,6}
Edit jack, joe
AppendPointValue(jack,0,joe)
If you are not familiar with Igor programming you are going to have to start up the learning curve. To start, execute this:
September 15, 2014 at 10:14 am - Permalink
Thanks hrodstein for your reply,
it solves partially what I'm trying to do. Your procedure only copy the first value of Ln_RateConv_time on both waves, Conv_0p1 and InvTemp_conv_0p1.
I need to copy the first value of Ln_RateConv_time on Conv_0p1 and the first value of Inv_Temp on InvTemp_conv_0p1.
After that, the second value of Ln_RateConv_time should be copied to Conv_0p2 and the second value on Inv_Temp on InvTemp_conv_0p2 and so on. So I think that I will need a for loop to achieve that.
I will try to do it by myself.
September 19, 2014 at 01:57 am - Permalink
// Appends
// Example:
// Make/O testSource = {1,2,3}
// Make/O testDest1 ={0}
// Make/O testDest2 ={1}
// Make/O testDest3 ={2}
// Edit testSource, testDest1, testDest2, testDest3
// AppendPointValues(testSource, "testDest")
Function AppendPointValues(source, destBaseName)
Wave source // e.g., Ln_RateConv_time
String destBaseName // e.g., "Conv_Op"
Variable numSourcePoints = numpnts(source)
Variable i
for(i=0; i<numSourcePoints; i+=1)
String destName
sprintf destName, "%s%d", destBaseName, i+1 // e.g., "Conv_Op1"
Wave dest = $destName // Create wave reference for dest
Variable value = source[i]
Variable numDestPoints = numpnts(dest)
dest[numDestPoints] = {value} // Append value
endfor
End
September 19, 2014 at 05:01 am - Permalink
Absolutely!!! I'm extremely grateful to you hrodstein again. You're a genius! :D
September 19, 2014 at 05:17 am - Permalink