How to insert data to a segment of an existing array (row vector) and generate several copies of the new vector?
Show older comments
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
Answers (1)
Jan
on 14 Jan 2013
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
Hamad Alhajri
on 14 Jan 2013
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!