How do I extract multiple vectors of different lengths from a single vector?

조회 수: 2(최근 30일)
Michael 2014년 2월 24일
댓글: Michael 2014년 2월 24일
I have a noise signal generated from a power supply rail that crosses zero at about 118 points. I want to extract vectors of the data from one negative zero crossing to the next to separate them out. They are from a PRBS7 pattern and I want to make multiple patterns from the one pattern by randomizing the order of the vectors.
My initial attempt to extract the vectors (Doesn't work because they are different lengths)
*ivddx is the noise vector, v is the vector that contains the zero crossing indices of ivddx
k=length(v)
for i = 1:k
if i==1
a(:,1)=ivddx(1):ivddx(v(1));
elseif i==k
a(:,k+1)=ivddx(v(k):end);
else
a(:,i)=ivddx(v(i):v(i+1)-1);
end
end

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

답변(1개)

Doug Hull 2014년 2월 24일
You should store each extracted vector in a cell array. The elements of a cell array do not care if they are different lenths:
>> a{1} = [1]
a =
[1]
>> a{2} = [2 2]
a =
[1] [1x2 double]
댓글 수: 1표시숨기기 없음
Michael 2014년 2월 24일
Thanks

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

범주

Find more on Descriptive Statistics 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!

Translated by