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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by John
on 22 Mar 2012

Hello,

If I had two vectors x1 and x2. How could I make vector x3 with all the elements of x2 except the first 3 elements and last 3 elements are from x1?

Many thanks

John

*No products are associated with this question.*

Answer by Thomas
on 22 Mar 2012

Is this what you wanted?

x1=1:10 x2=11:20 y=[x2(3:length(x2)) x1(1:length(x1-3))]

Show 2 older comments

John
on 22 Mar 2012

Thanks,

I'm trying to use it in this context but I'm getting an error for y2

Error using ==> horzcat

CAT arguments dimensions are not consistent.

but y1 and y2 are the same length and direction?

Thank you

for k = 1:length(files)

sch_cycle = xlsread(files{k}, 'Input_data');

nrows = size(sch_cycle,1)-1;

x = sch_cycle(:,1);

y = sch_cycle(:,2);

h=3;

N= size(sch_cycle,1);

r=ksr(x,y,h,N)

y1=r.f';

y2 = [y(1:3) y1(4:end-3) y(end-2:end)];

Answer by Oleg Komarov
on 22 Mar 2012

If same size:

x1(4:end-2) = x2(4:end-2);

Otherwise:

[x1(1:3); x2(4:end-2); x1(end-2:end)]

## 1 Comment

## Oleg Komarov (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/33159#comment_69717

Please give a specific title to your questions. Otherwise it's hard to tell wether you're double-posting or not.