Hello! I wanted to interpolate the NaN values within a matrix , and it works perfectly but I wanted also to interpolate the Inf entries so I have used the following line:
MyMatrix(isinf(MyMatrix))=NaN;
but then I get the following error :
Index exceeds matrix dimensions.
Error in interp1 (line 128)
extptids = Xq < X(1) | Xq > X(end);
could you give me any hints to what is causing this error and how can I interpolate the Inf entries without any errors . thank you ! Best regards!

댓글 수: 3

M
M 2017년 10월 31일
How is MyMatrix defined ?
Rik
Rik 2017년 10월 31일
Can you post a minimal working example, so we can try to reproduce this error?
Ano
Ano 2017년 10월 31일
편집: Ano 2017년 10월 31일
thank you for your replies! Here is the code I am using and the matrix subject of this error.
[rowN, colN]=size(MyMatrix);
colInd = 1: colN;%COLUMNS INDICES
IndnNAN = ~isnan(MyMatrix);
for r=1:rowN
MyMatrix(r,:)=interp1(colInd(IndnNAN(r,:)),MyMatrix(r,IndnNAN(r,:)),colInd,'linear');
end

댓글을 달려면 로그인하십시오.

답변 (1개)

M
M 2017년 10월 31일
편집: M 2017년 10월 31일

0 개 추천

Maybe the problem comes from the fact that
colInd(IndnNAN(r,:))
ans =
1×0 empty double row vector
and so is MyMatrix(r,IndnNAN(r,:))

댓글 수: 3

Ano
Ano 2017년 10월 31일
yes, I believe that is where the error comes from. any suggestions how to solve this problem ?!
M
M 2017년 10월 31일
Well, given your definition, either you have :
IndnNAN(r,:)
ans =
1×10 logical array
1 1 1 1 1 1 1 1 1 1
or
IndnNAN(r,:)
ans =
1×10 logical array
0 0 0 0 0 0 0 0 0 0
so colInd(IndnNAN(r,:)) will either be equal to 1: colN or it will be empty.
The question is, what did you want to do ?
Ano
Ano 2017년 10월 31일
first, I wanted to interpolate the NaN values and the code worked perfectly, then as I have mentioned I wanted to interpolate the consecutive Inf entries as they are taking an important part of the matrix but it is not working , so if I would reformulate my question I would say how can I interpolate consecutive entries of Inf values?!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

질문:

Ano
2017년 10월 31일

댓글:

Ano
2017년 10월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by