How to insert data to a segment of an existing array (row vector) and generate several copies of the new vector?

Here is the proposed code
N=10;
M=3;
x= randint(1,(N+1)*M,10);
l=[-1 ];
r=[-2];
d=[0];
p=[-3 -4 -5];
y=length(l)+length(r)+length(d)+length(p);
F=N+y;
z=[l p(1) x(1:5) d x(6:10) p(2:3) r];
x is the generated data row vector and I want to insert l,r,d and p as shown in z.as you see, I'm only using segments of x as I want to use the remaining elements of x at an adjacent row vector copy of z.Here is the desired out put
w=[l p(1) x(1:5) d x(6:10) p(2:3) r l p(1) x(11:15) d x(16:20) p(2:3) r l p(1) x(21:25) d x(26:30) p(2:3) r]
as you see, the iteration is performed M times so that the length of w is M*length(z). This is just a prototype of a longer row vectors with more specifications but I put this one for simplicity. Thanks

2 Comments

F and y are not used. They are just numbers ,they are lengths of vectors to give a better understanding of the dimensions.

Sign in to comment.

Answers (1)

The question is hard to understand for me. Do you mean something like this:
w1 = [l p(1) NaN(1, 5) d NaN(6, 10) p(2:3) r];
w = repmat(w1, 1, M);
gap = isnan(w);
x(gap) = x(1:sum(gap));

1 Comment

Thanks Jan. No, x has (N*M) entries. in this example N=10 and M=3, so it has 30. I'm trying to take first 10 entries to be stored in a new vector z with l,p,d and r distributed as shown in z. I want to use the next 10 entries of x in an adjacent vector with the same l,p,d and r , and so on creating a new vector of length 16+16+16=48 . I hope that helped.

Sign in to comment.

Categories

Asked:

on 14 Jan 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!