Hi
I want to a rearrange a single column of data into multiple columns of data as defined by a variable containing the indices. The columns will be of different lengths as the interval between the indices are not constant, therefore zero padding will occur at the end of each column. For example:
A = [1 2 3 4 5 6 7 8 9 10]';
B = [2 6 8 10];
I want C to equal:
C = [2 3 4 5 6; 6 7 8 0 0; 8 9 10 0 0]';
I can achieve this via a loop:
index.diff = (B(2:end)-B(1:end-1));
C= zeros(max(index.diff)+1,length(B)-1);
for i = 1:length(B)-1
index.start = B(i);
index.end = B(i+1);
index.range = index.end - index.start;
C(1:index.range+1,i) = A(index.start:index.end);
end
Is there non-loop method to do this?
I've tried various methods including using the following help on FEX:
1. PADCAT (<http://www.mathworks.com/matlabcentral/fileexchange/22909-padcat)>, which I can't quite get that to work as the input data for that is already in separate variables.
2. INSERTROWS (<http://www.mathworks.com/matlabcentral/fileexchange/9984-insertrows--v2-0--may-2008-)>, which I use to insert the zeros first into 'A' and then reshape to get 'C', but that still requires a loop to insert the zeros (at least that's what my limited knowledge allowed me to do).
Thanks in advance