# Create an Array of vectors within a for loop

4 ビュー (過去 30 日間)
Nick Costner 2019 年 11 月 19 日
Commented: 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.

#### 0 件のコメント

サインイン to comment.

### 採用された回答

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 2019 年 11 月 19 日
Thanks, it worked . Only i had to put a 'if' condition for the k.Because it exceeds the matrix dimensions.

サインイン to comment.

### More Answers (0)

サインイン してこの質問に回答します。

Translated by