11 views (last 30 days)

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

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 13 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_696992

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_696992

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697185

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697185

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697435

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697435

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697477

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697477

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697483

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697483

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697488

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697488

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697539

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697539

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697727

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697727

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697734

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697734

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697812

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697812

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697819

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697819

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697828

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697828

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697831

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/457878-why-do-i-get-nan-values#comment_697831

Sign in to comment.