Create an Array of vectors within a for loop

4 views (last 30 days)
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.

Accepted Answer

James Tursa
James Tursa on 19 Nov 2019
Edited: James Tursa on 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 Comment
Nick Costner
Nick Costner on 19 Nov 2019
Thanks, it worked . Only i had to put a 'if' condition for the k.Because it exceeds the matrix dimensions.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!