Asked by Stelios Fanourakis
on 22 Apr 2019 at 21:36

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')

Opportunities for recent engineering grads.

Apply Today
## 13 Comments

## madhan ravi (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_696992

## Stelios Fanourakis (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697185

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697435

## Stelios Fanourakis (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697477

## Stelios Fanourakis (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697483

## Stelios Fanourakis (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697488

## Rik (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697539

## Stelios Fanourakis (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697727

## Stelios Fanourakis (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697734

## Stelios Fanourakis (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697812

## John D'Errico (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697819

## Stelios Fanourakis (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697828

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697831

Sign in to comment.