indepvar and depvar are of inconsistent sizes with polyfitn
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
mohamed gryaa
le 4 Sep 2019
Commenté : Walter Roberson
le 15 Déc 2024
when i use polyfitn with matlab say indepvar and depvar are of inconsistent sizes and i don't now where i am wrong can yo help me?
this is the data:
x1=[2.2 2.2 2.2 2.44 2.49 2.48 2.45 2.2 2.39 2.38];
x2=[29.4 30.9 32.9 26.9 28 28.8 30.1 29.4 28.8 30];
y=[7.5 7.02 6.94 7.91 7.96 7.91 7.78 7.42 7.86 7.47];
p=polyfitn([x1,x2],y,1)
Error using polyfitn (line 172)
indepvar and depvar are of inconsistent sizes.
Réponse acceptée
Bjorn Gustavsson
le 4 Sep 2019
Yes, you send in an array [x1,x2] of size [1 x 20] and an array y of size [ 1 x 10] into polyfitn. The polyfitn version I have (a matlab-central submission by John d'Errico from 2006) gives me a more sensible result after transposing your inputs:
p=polyfitn([x1;x2]',y',1)
p =
ModelTerms: [3x2 double]
Coefficients: [1.5589 -0.11979 7.4607]
ParameterVar: [0.1693 0.0010284 2.9687]
ParameterStd: [0.41146 0.032068 1.723]
R2: 0.91523
RMSE: 0.10284
VarNames: {}
This was my curse when starting to use matlab - I solved it by the very sofisticated technique:
If it doesn't work transpose, transpose again until all combinations have been tried.
You might do the same but a more intelligent aproach is to check the documentation and input variables.
HTH
3 commentaires
Steven Lord
le 15 Déc 2024
Compare the sizes:
x1=[2.2 2.2 2.2 2.44 2.49 2.48 2.45 2.2 2.39 2.38];
x2=[29.4 30.9 32.9 26.9 28 28.8 30.1 29.4 28.8 30];
y=[7.5 7.02 6.94 7.91 7.96 7.91 7.78 7.42 7.86 7.47];
If the poster was using this File Exchange submission, what does its help text state about the requirements it places on its inputs?
% indepvar - (n x p) array of independent variables as columns
% n is the number of data points
% p is the dimension of the independent variable space
%
% IF n == 1, then I will assume there is only a
% single independent variable.
%
% depvar - (n x 1 or 1 x n) vector - dependent variable
% length(depvar) must be n.
If you passed [x1, x2] into polyfitn as the indepvar input argument, what are n and p?
[n, p] = size([x1, x2])
Is y (the depvar input argument) either an n x 1 or 1 x n vector? If we look at its size, it's clear that it is not.
sz = size(y)
If we transposed the x and y data:
[n, p] = size([x1.', x2.'])
sz = size(y.')
We see that y.' is an n x 1 vector. So polyfitn can operate on it and the combination [x1.', x2.'].
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!