>> x = table2array(Test1_x);
>> y = table2array(Test1_y);
I keep getting this error in polyfit. Here is the code and output from Matlab during a simple test. x and y should be arrays of real numbers.
-----------------------------------------
>> poly_fit_coef = polyfit(x, y, 1);
Error using ones
CLASSNAME input must be a valid numeric class name.
Error in polyfit (line 59)
V(:,n+1) = ones(length(x),1,class(x));
--------------------------------------
What is wrong here?
Thanks in advance for any help!
Jennifer

 채택된 답변

JFz
JFz 2015년 10월 26일

0 개 추천

I just got it! My x and y arrays have strings in them. I converted the strings to numbers and it worked!
x_d = str2double(x); y_d = str2double(y); poly_fit_coef = polyfit(x_d, y_d, 1);

댓글 수: 1

JFz
JFz 2015년 10월 26일
Thanks to Image and Star both for the help.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 10월 26일
편집: Image Analyst 2015년 10월 26일

0 개 추천

What does this say?
whos x
class(x)
whos y
class(y)
which -all polyfit

댓글 수: 4

Thank you so much for your quick reply. I typed the commands and here are results: whos x Name Size Bytes Class Attributes
x 1000x1 126012 cell
which -all polyfit
C:\Program Files\MATLAB\R2014b\toolbox\matlab\polyfun\polyfit.m
Image Analyst
Image Analyst 2015년 10월 26일
Like I thought, it wasn't a vector of numbers, but of strings.
Star Strider
Star Strider 2015년 10월 26일
Well, all it said was ‘cell’. That could be anything.
Image Analyst
Image Analyst 2015년 10월 26일
True. Since it came from table2array(), and we knew it wasn't a double, single, or an integer because it said "CLASSNAME input must be a valid numeric class name.", the most likely option that it would be is a cell array. Any cell array would generate this error - a cell array of strings, doubles, integers, etc.

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

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

질문:

JFz
2015년 10월 26일

댓글:

2015년 10월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by