??? Improper assignment with rectangular empty matrix.

I'm doing my report. Matlab is used to solve the question. My code like this:
function y=STFT(x,seg,step);
[Lx chan]=size(x);
maxi=(Lx-seg)/step;
for i=1:maxi;
X=x(1+(i-1)*step:seg+(i-1));
Z= X*step;
f=fft(Z);
P=f.*conj(f);
y(:,i)=P;
end
However, it show error exist at "y(:,i)=P; ". May i know how to solve it?
Besides that, is that other formula can i replace "X=x(1+(i-1)*step:seg+(i-1));"?
Hope can get the answer by today as my code have to submit tomorrow.
Thank you.

回答 (1 件)

David Young
David Young 2011 年 12 月 3 日

0 投票

I suspect your problem is that this line:
X=x(1+(i-1)*step:seg+(i-1));
should read
X=x(1+(i-1):step:seg+(i-1));

4 件のコメント

Goh
Goh 2011 年 12 月 3 日
but matlab there show error at y(:,i)=P. Why is it??
David Young
David Young 2011 年 12 月 3 日
If the size of X is computed incorrectly, that could cause an assignment error when you try to assign P to a column of y.
Goh
Goh 2011 年 12 月 3 日
i see. For the line
"X=x(1+(i-1)*step:seg+(i-1));
Z= X*step;"
is that got other way to write this formula?? Because what i posted is sample answer from lecturer, we need to change it. Any idea?
David Young
David Young 2011 年 12 月 5 日
It depends what the code is intended to do. It's hard to fix code without having a specification for the computation - more details of what you are aiming at would help.
By the way, I see that in your comment you show your original line of code, not my correction. Is that because the correction does not work?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

Goh
2011 年 12 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by