Clear Filters
Clear Filters

Need help for explanation of one command

2 views (last 30 days)
This is part of code
x = zeros(size(y)); % Making a row vector x which is having length equal to y and all contents of x are 0.
*x(1:length(ADSR)) = ADSR;* %----> What this line is doing, I know it is padding zeros but what is logic for that

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 23 Sep 2011
This is the code Walter provided in your previous question. It's a different way to do zero-padding.
Conventional Way: (assume ADSR is a 1xn vector)
x=ADSR; x=[ADSR,zeros(1,100)];
Walter's suggestion is to set x to be all zero first and then copy the value of ADSR to the beginning of x, that is what x(1:length(ADSR)) = ADSR does.
The potential issue is to make sure the length of x is bigger than the length of ADSR. Otherwise, x will end up with the same as ADSR.
  1 Comment
moonman
moonman on 23 Sep 2011
thanks Jiang
then copy the value of ADSR to the beginning of x, that is what x(1:length(ADSR)) = ADSR does.
This is what i was looking for

Sign in to comment.

More Answers (2)

Daniel Shub
Daniel Shub on 23 Sep 2011
If ADSR is of length N and y is of length M, then at the end, x will have at least length N (and possibly length M) depending on if N is greater or less then M. Now as for why you might want to pad zeros on ADSR, you haven't provided nearly enough information.

Jan
Jan on 23 Sep 2011
You know, what happens, and you ask, what the logic for it is. The question is not clear. Obvious any part in the program needs, that X contains the vector ADSR and some zeros to have the same length as y.

Tags

Community Treasure Hunt

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

Start Hunting!