Create an Array of vectors within a for loop

4 vues (au cours des 30 derniers jours)
Nick Costner
Nick Costner le 19 Nov 2019
Commenté : Nick Costner le 19 Nov 2019
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.

Réponse acceptée

James Tursa
James Tursa le 19 Nov 2019
Modifié(e) : James Tursa le 19 Nov 2019
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 commentaire
Nick Costner
Nick Costner le 19 Nov 2019
Thanks, it worked . Only i had to put a 'if' condition for the k.Because it exceeds the matrix dimensions.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by