copy and paste values from tables to a new table

Hi guys,

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.
That's probably very easy, but first we need to know how the data is organized in waves. A table in Igor is only a way to display data. Or did you mean that table0, table1 etc. are actually wave names? What kind of data is it (multidimensional, text data, in different folders etc...)? Can you post a example experiment here with instructions what you want to copy to where?
chozo wrote:
That's probably very easy, but first we need to know how the data is organized in waves. A table in Igor is only a way to display data. Or did you mean that table0, table1 etc. are actually wave names? What kind of data is it (multidimensional, text data, in different folders etc...)? Can you post a example experiment here with instructions what you want to copy to where?


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!
rate.pxp (2.55 MB)
First, I recommend that you think in terms of waves (named arrays of values in memory) rather than tables. A wave can exist without a table. A table is just a way to view a wave, like a graph. So you are not copying from one table to another but from one wave to another.

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:
Function Demo1()
    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:
Function AppendPointValue(source, sourcePoint, dest)
    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 jack = {1,2,3}
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:
DisplayHelpTopic "Igor Pro Programming"


hrodstein wrote:
First, I recommend that you think in terms of waves (named arrays of values in memory) rather than tables. A wave can exist without a table. A table is just a way to view a wave, like a graph. So you are not copying from one table to another but from one wave to another.

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:
Function Demo1()
    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:
Function AppendPointValue(source, sourcePoint, dest)
    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 jack = {1,2,3}
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:
DisplayHelpTopic "Igor Pro Programming"



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.
I think this is what you need:
// AppendPointValues(source, destBaseName)
// 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

hrodstein wrote:
I think this is what you need:
// AppendPointValues(source, destBaseName)
// 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



Absolutely!!! I'm extremely grateful to you hrodstein again. You're a genius! :D