# Truncating a vector from an addressed element in MatLab

#### edwrai

hi,
in MatLab, if you have x and y vectors and want to address an element in vector x, let's say i>=3 from which to construct a new vector x that starts from the addressed element until the last element and at the same time construct a new y vector corresponding to the new x vector?

x=[1 2 3 4 5 6 7]
y=[7 6 5 4 3 2 1]
new x should be=[4 5 6 7]
and new y =[4 3 2 1 ]

Maybe using an array=[x y]?

Any answer would be very much appreciated.

Related MATLAB, Maple, Mathematica, LaTeX, Etc News on Phys.org

#### MATLABdude

Don't know if this is still useful or not, but you'd have to use the colon (:) operator. See the Mathworks page for more information and usage:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/colon.html

In your case, you'd use the following:
>> x = x(3:5);
>> y = y(3:5);

Once you read through the above page, you'll understand why.

### Want to reply to this thread?

"Truncating a vector from an addressed element in MatLab"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving