Problems using polyfit in a for loop
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bob
am 14 Dez. 2014
Beantwortet: Star Strider
am 14 Dez. 2014
I am getting an error when I try to run this polyfit. I think the problem is the values I am putting for xfit1 in the polyfit formula. What values should I put for xfit1 to fix my code?
Error Message: Error using polyfit (line 50) X and Y vectors must be the same size.
My Code:
Z=[3 1];
for i=1:length(Z);
A(i)=Z(i)+2;
B(i)=Z(i)-7;
xfit=[0 1];
yfit1(:,i)=[A(i),B(i)]
pfit1(:,i)=polyfit(xfit1,yfit1(:,i),1);
end
0 Kommentare
Akzeptierte Antwort
Star Strider
am 14 Dez. 2014
You had the indexing reversed in ‘yfit1’ and ‘pfit1’. This works:
Z=[3 1];
for i=1:length(Z);
A(i)=Z(i)+2;
B(i)=Z(i)-7;
xfit1=[0 1];
yfit1(i,:)=[A(i),B(i)];
pfit1(i,:)=polyfit(xfit1,yfit1(i,:),1);
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!