MATLAB: Error using Polyfit, X and Y vectors must be the same size errorpolyfit plot(flip(AdjClose))y = flip(AdjClose)x = 1:503;polyfit(y,x,0) x is a 503*1 double and y is a 1*503 double. I wonder how can I make them the same size? Best Answer You can use the transpose function. For example, you could have doney = flip(AdjClose).' Related SolutionsMATLAB: Polyfit, polyval and plot Because the syntax should bepolyfit(x,y,N) and notpolyfit(y,x,N) Here is some code that illustrates the fix:x = 1:503; y = 250 + 0.02*x + 0.005*x.^2 + 0.2*rand(1,503).*x; figure polyfit(y,x,0); coef1 = polyfit(x,y,0); y1 = polyval(coef1,x); hold on plot(x,y,'.'); plot(x,y1); polyfit(x,y,1); coef2 = polyfit(x,y,1); y2 = polyval(coef2,x); plot(x,y2); polyfit(y,x,2); coef3 = polyfit(x,y,2); y3 = polyval(coef3,x); plot(x,y3); MATLAB: MATLAB polyfit, palyval not working correctly p = polyfit(temp,carbonSteel,3);y = polyval(p,carbonSteel);What did you build? A model, that predicts carbonsteel, as a function of temp. So temp is the INDEPENDENT variable.Now, you want to predict the dependent variable, as as a function of temp. So you need to do this:y = polyval(p,temp);plot(temp,carbonsteel,'bo',temp,y,'r-')What you did, as you did it, makes no sense in context of the model you built.. Related QuestionFitting data using polyfit, nlfitCreating a symbolic variable, then using it as a real variableWhat is wrong with thisFzero, Operands to the || and && operators must be convertible to logical scalar values.
Best Answer