Why do I get NaN values?
이전 댓글 표시
I have used exactly the same code for Sheet 5 and different column names and I get numerical values but when I use it at Sheet 6 and slightly adjacent columns but the same number of rows I get NaN.
Any idea why this happens?
x1 = readtable('ValidationTest.xls', 'Sheet',6, 'Range','N2:N385 ');
y1 = readtable('ValidationTest.xls', 'Sheet',6, 'Range','A2:A385 ');
x2 = readtable('ValidationTest.xls', 'Sheet',6, 'Range','O2:O868');
y2 = readtable('ValidationTest.xls', 'Sheet',6, 'Range','B2:B868');
P1 = polyfit(x1{:,:}, y1{:,:}, 6 )
P2 = polyfit(x2{:,:}, y2{:,:}, 6)
allX = unique([x1{:,:}; x2{:,:}]);
Pd = polyval(P1, allX) - polyval(P2, allX)
P11 = polyval(P1, allX)
P22 = polyval(P2, allX)
hold on
plot(allX, Pd, 'b')
plot(allX, P11, 'g')
plot(allX, P22, 'r')
댓글 수: 13
madhan ravi
2019년 4월 22일
I don’t see how a help can be offered without you providing any data file.
Stelios Fanourakis
2019년 4월 23일
Walter Roberson
2019년 4월 23일
A copy of the data file would make it much easier for us to investigate.
Stelios Fanourakis
2019년 4월 23일
Stelios Fanourakis
2019년 4월 24일
Stelios Fanourakis
2019년 4월 24일
Rik
2019년 4월 24일
You still haven't attached the file (or a smaller file that reproduces the issue).
Stelios Fanourakis
2019년 4월 24일
Stelios Fanourakis
2019년 4월 24일
Stelios Fanourakis
2019년 4월 24일
John D'Errico
2019년 4월 24일
편집: John D'Errico
2019년 4월 24일
The file you attached has only one page in it. If I extract those 4 variables, it appears that y2 is constant at 4.8. ABSOLUTELY constant.
If I plot x1 and y1, I see this discreet mess:

That is what this is all about? An absolutely copnstant function, and a that mess?
Sorry, but how do you justify fitting a 6th degree poltynomial to that? You have asked how many questions on this so far?
Stelios Fanourakis
2019년 4월 24일
편집: Stelios Fanourakis
2019년 4월 24일
Walter Roberson
2019년 4월 24일
That code is not set up to read the VTest.xlsx file you provided.
The earlier code was set up to read it (once the file name was changed), but it did not take into account that two of the columns were shorter than the others.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!