# Assigning part of one wave to another wave

I thought I knew how to do this, but it is not working. I am aiming to take make a new wave who's points are data points from a larger wave.

the code looks approximately like this

Wave2=wave1[leftrange,rightrange].

The compiler keeps throwing the error that it wants there to be a right bracket after where i have substituted the word "left range" ----> wave2=wave1[leftrange], but that will just make wave2 a single-valued wave, which is not what i want. I want it to just be filled with the indicated range from wave1

I'm sorry that I am asking this here as it seems trivial

The right-hand-side doesn't express the point range. That's controlled by the left side. So on the right, p will range from 0 to numpnts(lhs)-1. To get what you want, you would write something like

`Wave2=wave1[p+leftrange]`

If Wave2 has the right number of points, then rightrange takes care of itself.

But you should also consider

`Duplicate/R=[leftrange, rightrange] wave1, wave2`

Using Duplicate for this task is generally faster, and more straightforward.

Wave indexing is your friend here. See the following snippet as an example

function foo(leftrange, rightrange)
variable leftrange, rightrange
variable npts=rightrange-leftrange
make/O/N=500 wave1=x
make/O/N=(npts+1) wave2=wave1[p+leftrange]
end

This assumes your left and right values are both included. The last line contains the crux of the solution. Your question seems to indicate point indexing. Scaled ranges can be accommodated using x2pnt(waveName, x1 ). You also might want to do some preliminary bounds checking if the sub-wave extraction is in a function.