Duplicate the portion of a wave displayed in a graph

To use this code, paste it into an Igor procedure file and compile the procedures. Use the marquee tool or ModifyAxis dialog box to change the X range of the graph to display only the portion of the wave you wish to duplicate. When you are satisfied with what is displayed, right click on the trace and choose Partial duplicate -> Visible portion. Note that this will only work as expected for 1D waves.

// Usage:  Right click on a trace and choose Partial duplicate -> Visible portion
// And the part of the wave that is currently within the x range of the graph
// window will be duplicated into a new wave.
Menu "TracePopup"
    SubMenu "Partial duplicate"
        "Visible portion", /Q, DuplicateVisiblePortion()
    End
End

Function DuplicateVisiblePortion()
    // Determine which trace the user selected.
    GetLastUserMenuInfo
    String graphName = S_graphName
    String traceName = S_traceName
   
    // Call function to get the range to duplicate.
    Variable xMinPnt, xMaxPnt
    GetXRangeOfTracesXAxis(graphName, traceName, xMinPnt, xMaxPnt)
   
    WAVE targetWave = TraceNameToWaveRef(graphName, traceName)
   
    // Duplicate the wave.
    WAVE/Z destWave
    String destWaveFullPath = DuplicateSpecifiedPortionOfWave(targetWave, xMinPnt, xMaxPnt)
   
    // Print a summary of what was done to the history window.
    printf  "Duplicated %s[%d,%d] into %s\r", GetWavesDataFolder(targetWave, 2), xMinPnt, xMaxPnt, destWaveFullPath
End

Function/S DuplicateSpecifiedPortionOfWave(targetWave, xMinPnt, xMaxPnt)
    WAVE targetWave
    Variable xMinPnt
    Variable xMaxPnt
   
    // Create a name for the destination wave.
    String destWaveName = GetWavesDataFolder(targetWave, 1) + PossiblyQuoteName(UniqueName(CleanupName(NameOfWave(targetWave) + "Copy", 1), 1, 0))
   
    Duplicate/R=[xMinPnt, xMaxPnt] targetWave, $(destWaveName)
    WAVE destWave = $(destWaveName)

    return GetWavesDataFolder(destWave, 2)      // Return the full path to the new wave.
End

Function GetXRangeOfTracesXAxis(graphName, traceName, xMinPnt, xMaxPnt)
    String graphName, traceName
    Variable &xMinPnt, &xMaxPnt     // Both passed by reference

    WAVE targetWave = TraceNameToWaveRef(graphName, traceName)
   
    // Determine X limits of trace that is visible in graph window.
    String info = TraceInfo(graphName, traceName, 0)
    String xAxis = StringByKey("XAXIS", info, ":", ";")

    GetAxis/W=$(graphName)/Q $(xAxis)
    if (V_flag == 0)        // xAxis is actually used in the graph--this should always be true
        // Convert axis values into point values
        xMinPnt = x2pnt(targetWave, V_min)
        xMaxPnt = x2pnt(targetWave, V_max)
    endif
End

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More