Error Index exceeds matrix dimensions

Data 1000x100
for i = 2:length(x)-1
[x ,y] = min(Data(i));
if x(i) < x(i-1)+10 && x(i) < x(i+1)+10
x(i)=x(i);
end
end
Index exceeds matrix dimensions.
Hello! I have a matrix, I'm trying to create a loop that I need for a maximum of x values, but it gives me such an error

1 件のコメント

Adam
Adam 2019 年 8 月 20 日
With breakpoints or pause on errors it is easy to find these things looking on command line.
You shouldn't use length in this situation. size( x, 1 ) is much safer if that is what you mean, although x is undefined at that point in the code snippet you gave us also. Your if statement currently does nothing other than assign something to itself.

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

回答 (1 件)

Jan
Jan 2019 年 8 月 20 日

0 投票

After
[x ,y] = min(Data(i));
x is a scalar. Then x(i) cannot work for i > 1.
By the way, as Adam has said alread, x(i)=x(i) does nothing, so the purpose of the code is unclear.

カテゴリ

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

製品

タグ

質問済み:

2019 年 8 月 20 日

回答済み:

Jan
2019 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by