Keep getting error in polyfit

2 vues (au cours des 30 derniers jours)
JFz
JFz le 26 Oct 2015
Commenté : Image Analyst le 26 Oct 2015
>> 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

Réponse acceptée

JFz
JFz le 26 Oct 2015
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 commentaire
JFz
JFz le 26 Oct 2015
Thanks to Image and Star both for the help.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 26 Oct 2015
Modifié(e) : Image Analyst le 26 Oct 2015
What does this say?
whos x
class(x)
whos y
class(y)
which -all polyfit
  4 commentaires
Star Strider
Star Strider le 26 Oct 2015
Well, all it said was ‘cell’. That could be anything.
Image Analyst
Image Analyst le 26 Oct 2015
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by