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
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!