MATLAB: Using delay seq to shift data with different delay conditions

arraysdelayseqmatricesmatrix manipulation

Hi! I have a matrix that has 10 columns and 50 rows. I want to introduce a delay in columns 2,3 and 4, and then again in columns 7,8,9 and 10. In column 2, I want a delay by one sample, in column 3 I want a delay by 2 samples, in column 4 I want a delay of 3 samples, and similarly in columns 7,8,9 and 10 I want delays of 4,5,6 and 7 samples. Is there a way I could use delayseq to automate this process? Thanks in advance!

Best Answer

Hi Zuha,
Here is the code for what is looked for:
a = rand(50,10);
shift = [0 1 2 3 0 0 1 2 3 4]; % Use the shift required for eah column
a1 = zeros(54,10);
a1(1:50,shift==0) = a(:,shift==0);
a1(2:51,shift==1) = a(:,shift==1);
a1(3:52,shift==2) = a(:,shift==2);
a1(4:53,shift==3) = a(:,shift==3);
a1(5:54,shift==4) = a(:,shift==4);
% Or this can be done through loop
a2 = zeros(size(a,1)+max(shift),size(a,2));
for i = 1:size(a,2)
a2(shift(i)+1:size(a,1)+shift(i),i) = a(:,i);
end
Hope this helps.
Regards,
Sriram