Using delay seq to shift data with different delay conditions

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!

댓글 수: 4

May i know what does delay mean here? Any small example for the situation.
Hi! Thanks for responding! By delay, I mean that I want to shift the samples down the columns. For example, suppose I had a matrix [2 3 4; 5 6 7; 8 9 10 ]. I want to shift the second and third columns down. For example, I want to shift the second column down by introducing 1 zero. I want to shift the third column down by introducing 2 zeros. Basically I want to do what circshift does, WITHOUT the circular aspect.
So, to see if i understand correctly, you want the output to be [2 0 0;5 3 0;8 6 4;0 9 7;0 0 10], for the input matrix you placed. Am i right?
Yes exactly!

댓글을 달려면 로그인하십시오.

 채택된 답변

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

댓글 수: 3

Hi, that gives me this kind of matrix:
I see that columns 5 and 6 are both not being delayed. I want column 5 to not be delayed, and column 6 to be delayed. Is there any reason why this might be happening?
Sriram Tadavarty
Sriram Tadavarty 2020년 3월 20일
편집: Sriram Tadavarty 2020년 3월 20일
Hi Zuha, In the shift variable provide the shift as non-zero for the sixth column and that would solve. The update to shift vector in the answer will help. Let me know if the sixth value changed from 0 to the value you want and you get the expected answer. And then, seeing the image below you don't want the number of rows to be changed, so after the loop, or after those calculations, update a1 = a1(1:50,1:10); and a2 = a(1:size(a,1),1:size(a,2)); Hope this helps.
Thanks so much! That helped.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Zuha Yousuf
Zuha Yousuf 2020년 3월 19일

0 개 추천

Basically, something like this. The first column after the one not being delayed should always have one 0, the next always have two 0s and so on. I've attached a picture for clarity.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2020년 3월 19일

댓글:

2020년 3월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by