Create an Array of vectors within a for loop

조회 수: 4 (최근 30일)
Nick Costner
Nick Costner 2019년 11월 19일
댓글: Nick Costner 2019년 11월 19일
Hello
I am a student, i was given a vocal signal of 5000x1 which i need to get it's power spectral density using pwelch function. The frequency of the signal changes over time . So i was told to cut it into 50 segments of 100 points and use the pwelch function on each of these segments.So that at the end i can plot the frequencies i got from every segment as a function of time.
The issue i get is in the syntax , i tried this :
for j=0:100:5000;
i=[1:50];
[PXX(i),F(i)]=pwelch(data(1+j:100+j),20,4,2^13,1000);
end
but i get this as a result "In an assignment A(I) = B, the number of elements in B and I must be the same."
I know that the output of the pwelch function are two column vectors of nx1 size.What i want to do is to create 50 elements of nx1,only i dont know how to write it.

채택된 답변

James Tursa
James Tursa 2019년 11월 19일
편집: James Tursa 2019년 11월 19일
If you want to store the column vectors, you could use cell arrays. E.g.,
k = 1;
for j=0:100:5000;
:
[PXX{k},F{k}]=pwelch(data(1+j:100+j),20,4,2^13,1000);
k = k + 1;
Then downstream in your code you can use the curly brace { } syntax to get at the column data.
  댓글 수: 1
Nick Costner
Nick Costner 2019년 11월 19일
Thanks, it worked . Only i had to put a 'if' condition for the k.Because it exceeds the matrix dimensions.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spectral Estimation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by