Error using interp1 on MATLAB R2015b for Mac

8 ビュー (過去 30 日間)
Rosa Santos
Rosa Santos 2017 年 8 月 18 日
コメント済み: Walter Roberson 2017 年 8 月 22 日
Hi! I am a newbie on matlab trying to interpolate temp & pressure profile data and its getting the error:
Error using griddedInterpolant
The coordinates of the input points must be finite values; Inf and NaN are not permitted.
Error in interp1 (line 161)
F = griddedInterpolant(X,V,method);
Error in RSatto (line 30)
pressI = interp1(A(~nanx),B(~nanx),x,'nearest','extrap');
This is my code:
clear; clc;
%cd /Users/Rosinha/Documents/GoBLE/Dados&Resultados/GoBLE-ATTO_RS-2015/ProfessoraRosa/ATTO/ATTO_alterados/ATTO;
pwd
%raw = dir('2015*.dat');
%x=(0:50:30000)'; %Intervalo usado para Interpolação
grd = 180 ./ 3.141593; rad = 3.141593 ./ 180;
Dz=50;
g=9.8;
%%Lendo arquivos *.dat
atto = load('201510311100.dat');
%%****** Formato *******
% alt(m) press(hPa) T(oC) RH(%) Td(oC) Tvi(oC) densidade(kg/m3) ff(m/s) dd(o)
% uvel(m/s) vvel(m/s)
alt = atto(:,1); %press = atto(:,2); T = atto(:,3); RH = atto(:,4);
%Td = atto(:,5); Tvi = atto(:,6); densidade = atto(:,7);
%ff = atto(:,8); dd = atto(:,9); uvel = atto(:,10); vvel = atto(:,11);
%%******* Interpolação *******************
x=(0:50:numel(alt))'; %intervalo de interpolação
%x=(0:50:3500)'
C = unique(atto(:,1:2),'rows');
nanx=isnan(C(:,2));
A=C(:,1);
B=C(:,2);
pressI = interp1(A(~nanx),B(~nanx),x,'nearest','extrap');
I typed "dbstop if naninf"and got the following msg:
NaN/Inf breakpoint hit for fullfile.p on line 28.
29 persistent fileSeparator;
29 persistent fileSeparator;
I have no idea what I'm doing wrong! Could someone help me? Thanks!

採用された回答

Walter Roberson
Walter Roberson 2017 年 8 月 18 日
Your code is protecting against B being nan, but it is not protecting against A being nan, and is not protecting against inf on the input. I recommend changing
nanx=isnan(C(:,2));
to
nanx = ~all(isfinite(C),2);
  2 件のコメント
Rosa Santos
Rosa Santos 2017 年 8 月 19 日
Thanks guys! I tried doing what Walter and Chad recommended but it didn't work! In both cases I get the error msg:
Error using griddedInterpolant The grid vectors are not strictly monotonic increasing. Error in interp1 (line 161) F = griddedInterpolant(X,V,method); Error in RSatto (line 31) pressI = interp1(A(~nanx),B(~nanx),x,'nearest','extrap');
Walter Roberson
Walter Roberson 2017 年 8 月 19 日
nanx = ~all(isfinite(C),2);
tempC = sort( C(nanx,:), 'rows');
A = tempC(:,1);
B = tempC(:,2);
pressI = interp1(A, B, x, 'nearest', 'extrap');

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

その他の回答 (2 件)

Chad Greene
Chad Greene 2017 年 8 月 18 日
What do you get if you type
sum(A(~nanx))
I have a feeling there are some NaNs in there. Perhaps the line just above it should be
nanx=isnan(C(:,1));
  1 件のコメント
Rosa Santos
Rosa Santos 2017 年 8 月 19 日
Thanks guys! I tried doing what Walter and Chad recommended but it didn't work! In both cases I get the error msg:
Error using griddedInterpolant The grid vectors are not strictly monotonic increasing. Error in interp1 (line 161) F = griddedInterpolant(X,V,method); Error in RSatto (line 31) pressI = interp1(A(~nanx),B(~nanx),x,'nearest','extrap');

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


Rosa Santos
Rosa Santos 2017 年 8 月 22 日
Thanks guys! I tried doing what Walter and Chad recommended but it didn't work! In both cases I get the error msg:
Error using griddedInterpolant The grid vectors are not strictly monotonic increasing. Error in interp1 (line 161) F = griddedInterpolant(X,V,method); Error in RSatto (line 31) pressI = interp1(A(~nanx),B(~nanx),x,'nearest','extrap');
  2 件のコメント
Torsten
Torsten 2017 年 8 月 22 日
The error message clearly states that the vector A is not strictly increasing as it should be, i.e.
A(i) < A(i+1) for i=1,...,numel(A)-1.
So you will have to sort A first and rearrange B accordingly.
Best wishes
Torsten.
Walter Roberson
Walter Roberson 2017 年 8 月 22 日
You seem to have overlooked my comment to my answer, where I do a sort

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by