Error using polyfit (line 44) The first two inputs must have the same number of elements

19 Ansichten (letzte 30 Tage)
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

Antworten (2)

Matt J
Matt J am 15 Mai 2022
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 Kommentare

Melden Sie sich an, um zu kommentieren.


Matt J
Matt J am 16 Mai 2022
Take a look at this.
  6 Kommentare
Youssef Aberkane
Youssef Aberkane am 17 Mai 2022
i had a bug so i restarted my laptop when i run the code this error pops up
Torsten
Torsten am 17 Mai 2022
Bearbeitet: Torsten am 17 Mai 2022
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by