Error using polyfit (line 44) The first two inputs must have the same number of elements
18 次查看(过去 30 天)
显示 更早的评论
I don't see where is the problem.
function PolynomeButtonPushed(app, event)
fct = app.LafonctionEditField.Value;
I = linspace(app.MinEditField.Value,app.MaxEditField.Value,app.NombredespointsEditField.Value);
n = app.LodredupolynomeEditField;
polynome = polyfit(I,fct,n);
app.EditField.Value = polynome;
end
end
0 个评论
回答(2 个)
Matt J
2022-5-15
The error message has given you a big clue to where the problem is. Did you examine/verify the contents of I and fct to see if they have the same length?
8 个评论
Matt J
2022-5-16
6 个评论
Torsten
2022-5-17
编辑:Torsten
2022-5-17
Is it not possible that you just report the six outputs of the function written to screen (I added three in the code) ?
As far as I can see, "n" is not of class "double", but of class "matlab.ui.control.NumericEditField". This produces one error in polyfit. Do you know how to convert "n" to type "double" ? Most probably, n=double(n) should do in your code. Or use "cast". And most probably, the same is necessary for I.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!