Index exceeds the number of array elements

2 ビュー (過去 30 日間)
Behrang Elgameh
Behrang Elgameh 2019 年 10 月 17 日
コメント済み: Adam 2019 年 10 月 17 日
I just get the error for using interpolation
Here is the code
Fs=1000000;
dt=1/Fs;
vt=[0:dt:tmax]';
data1=[];
data1(:,1)=vt;
[A, index] = unique (A);
data1(:,2)=interp1(T,A(index),vt);
A and T are defined from a txt file
Thanks

回答 (1 件)

Adam
Adam 2019 年 10 月 17 日
編集済み: Adam 2019 年 10 月 17 日
[A, index] = unique (A);
replaces what was in A with the result of unique (i.e. all the non-unique values removed)
So indexing further into this as
A(index)
will result in this error since index will contain values upto the orginal size of A before the non-unique elements were removed, and is un-necessary as you should just use A (or assign the output of unique to a different variable instead of overwriting A and index into that other variable instead).
  2 件のコメント
Behrang Elgameh
Behrang Elgameh 2019 年 10 月 17 日
Dear Adam,
Thank you so much for your answer,
I just used "unique" as I was facing the error "The grid vectors must contain unique points" related to interp1
Adam
Adam 2019 年 10 月 17 日
That's fine, but you still need to do either of the options I suggested. Don't do an in-place over-write of your data, then use an index list that was created for the original data on top of that.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by