# creating Arrys from another big array

20 views (last 30 days)
Rica on 7 Jul 2015
Answered: Guillaume on 7 Jul 2015
Hi, I have an array A of the size 1X1000. and i have a vector of Index: index=[1 25 40 63 77 99 100]
is there any easy way in matlab to create such arrays:
Arr1=(A(index(1)): A(index(2)))
Arr2=(A(index(2)): A(index(3)))
Arr3=(A(index(3)): A(index(4)))
and so on...

Azzi Abdelmalek on 7 Jul 2015
Post a small example
Rica on 7 Jul 2015
sorry i mad a mistake:this is the corrected question: Hi, I have an array A of the size 1X100 . and i have a vector of Index: index=[1 25 40 63 77 99 100]
is there any easy way in matlab to create such arrays:
Arr1=(A(index(1)): A(index(2)))
Arr2=(A(index(2)): A(index(3)))
Arr3=(A(index(3)): A(index(4)))
and so on...

Thorsten on 7 Jul 2015
Edited: Thorsten on 7 Jul 2015
index=[1 25 40 63 77 99 100]
A = rand(1,100);
for i = 1:numel(index)-1
B{i} = A(index(i):index(i+1));
end
Note that the index(2), index(3), ... index(N-1) elements occur twice in B, such that B has numel(index) -2 elements more than A.

Guillaume on 7 Jul 2015