move segment of a wave/graph
Tuland
I tried the segment mover (cntl + edit wave ) in Poly tool but it does only for adjacent points.
Is there any way for example by placing two cursors on the graph at points say at (x1,y1) and (x2,y2) and then shifting (visually/by dragging the curve portion) all the points within (x1,y1) and (x2,y2) to new location (x1,y1-5) ...(x2,y2-5) where all the points within (x1, y1) and (x1,y2) also moves by the same amount ( -5) .
The arithmatic panel can do the shift but for it works on whole graph, is there any way to do it on section of a graph.
Here is a function that does it programmatically:
Wave xWave, yWave
Variable startX, endX
Variable offset
Variable numPoints = numpnts(xWave)
Variable i
for(i=0; i<numPoints; i+=1)
Variable xval = xWave[i]
if (xVal>=startX && xVal<=endX)
yWave[i] += offset
endif
endfor
End
Here is another function that does the same thing but much faster:
Wave xWave, yWave
Variable startX, endX
Variable offset
yWave = (xWave>=startX && xWave<=endX) ? yWave+offset : yWave
End
Execute this for help on ?:
February 25, 2012 at 08:04 am - Permalink
I tried to get xwave and ywave from cursor but it didnt work. Somehow I didnt able to define the function properly.
Can you put some light !!
Menu "Segment Move"
"Move Segment ...", AddToXYPairSegment2("", "", "", "",10)
End
Function AddToXYPairSegment2(XWave, YWave, startX, endX, offset)
Variable offset
WAVE/Z w = CsrWaveRef(A)
if (!WaveExists(w)) // Cursor is not on any wave.
return NaN
endif
Variable startX = xcsr(A)
Variable endX = xcsr(B)
Wave YWave = w
Wave XWave = CsrXWave(A)
YWave = (XWave>=startX && XWave<=endX) ? YWave+offset : YWave
DisplayYWave vs XWaveA
End
February 25, 2012 at 09:26 am - Permalink
Function AddToXYPairSegment3(offset)
Variable offset
WAVE/Z yWave = CsrWaveRef(A)
if (!WaveExists(yWave)) // Cursor is not on any wave
return -1
endif
WAVE/Z xWave = CsrXWaveRef(A)
if (!WaveExists(xWave)) // Cursor is not on XY pair
return -1
endif
Variable startX = hcsr(A)
Variable endX = hcsr(B)
if (startX > endX)
return -1
endif
YWave = (XWave>=startX && XWave<=endX) ? YWave+offset : YWave
return 0
End
February 25, 2012 at 10:47 am - Permalink
February 25, 2012 at 01:17 pm - Permalink