MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

# Copy numbers vector to vector

Asked by klipya on 3 Aug 2012

Hello! If I have a vector and I need to copy some numbers from another vector how can I do it?

For example, this is what I've done:

```graph1= zeros(1:100)
i1=50
i2=55
I(i1:i2)=v1(240:245)
```

v1= v1 is another vector and I want to copy in the 'graph1' (on the positions 50 to 51), the numbers of the vector v1 in the position 240:245.

thanks a lot,

## Products

No products are associated with this question.

## 2 Answers

Answer by Daniel on 3 Aug 2012
Edited by Daniel on 3 Aug 2012
Accepted answer

You need to read the documentation. This is really a simple problem and your code is close.

```v1 = randn(1, 255);    % We need this in order to do the copy
graph1= zeros(1, 100); % Note this is not 1:100
i1=50;
i2=55;
graph1(i1:i2)=v1(240:245); % Your code had I, which you never describe.
```

## 1 Comment

klipya on 6 Aug 2012

Thanks Daniel, now it works!

Answer by venkat vasu on 3 Aug 2012

graph1(50:0.2:51)=v1(240:245);

## 3 Comments

klipya on 3 Aug 2012

Thanks venkat! What's 0.2?

venkat vasu on 3 Aug 2012

i think you want to insert from 240-245th position vector in b/w 50-51 position. so in b/w 50-51 like that only we can insert the vector.

Walter Roberson on 10 Aug 2012

It is not possible to use non-integral subscripts for a vector, so this code will not work.

Contact us