Asked by Kirti
on 26 Nov 2012

Hi all, I am having y=[1 2 3 4 5 6 7 8 9 10] as data. i want to write array x1 =[ 1 2 3 4 5] x2 =[2 3 4 5 6] x3= [3 4 5 6 7] like this upto x6 =[6 7 8 9 10]. please help me to create this using matlab. I tried as follows :n=10;k=6;m=5; for i=1:k for j=i:i+m-2 x[i]= a(j); end end but it is not working!!

*No products are associated with this question.*

Answer by Ilham Hardy
on 26 Nov 2012

Accepted answer

ya = [1,2,3,4,5,6,7,8,9,10];

for iy = 1:(length(ya)/2)+1 xa(iy,:) = ya(iy:4+iy); end

Answer by Amin Bashi
on 26 Nov 2012

y=[1 2 3 4 5 6 7 8 9 10] x = y([1:5;2:6;3:7;4:8;5:9;6:10])

Answer by Muruganandham Subramanian
on 26 Nov 2012

Hi..

try this code

a=[1:10];

for i=1:numel(a)

if i==a(1)

disp(a)

elseif i<=6

a(1)=[];

disp(a)

else

break;

end

end

Answer by Kirti
on 26 Nov 2012

Thanks liham Hardy

Kirti
on 27 Nov 2012

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

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments