Whats wrong with my code?

1 回表示 (過去 30 日間)
Dan Lecoutre
Dan Lecoutre 2023 年 3 月 29 日
コメント済み: Star Strider 2023 年 3 月 29 日
I'm using the 10x2 matrix sem to indicate different sections of a time signal that I am computing the fft of. There is 10 sections so I'm using a for loop to plot the 10 different sections on the same figure.
So I've ran the code above and I've received the error message as can be seen in the command window. In the workspace window it says i=4 when this shouldn't be a saved variable and start and finish are also saved as scalars in the workspace when they shouldn't be. It is this that has led me to believe there is something wrong with my for loop.
  2 件のコメント
Rik
Rik 2023 年 3 月 29 日
Have a read here and here. It will greatly improve your chances of getting an answer.
I can't run an image file. Try to make a MWE so we can run your code without any other dependencies and can reproduce your issue. The best way to do this is to use the code section in the editor and use the run button. That way you can make sure we will see the same error message as you do.
Star Strider
Star Strider 2023 年 3 月 29 日

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

回答 (1 件)

Cris LaPierre
Cris LaPierre 2023 年 3 月 29 日
You are trying to index to an element that does not exist. The error message tells you the max index possible is 5000001, yet your index value finish has a value of 19557943.
Here's a simplified example.
a=1:3
a = 1×3
1 2 3
% works
a(3)
ans = 3
% your error
a(30)
Index exceeds the number of array elements. Index must not exceed 3.

カテゴリ

Help Center および File ExchangeTransforms についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by