There were several fundamental issues with your code. I fixed them.
P1=2;
P2=10;
P3=50;
C1=1.5;
C2=1.5+(((P1:P2)-P1)*0.5);
C3=5.5+(((P2:P3)-P2)*0.3);
x=[1 linspace(2,10,length(P1:P2)) linspace(10,50,length(P2:P3))];
y=[C1 C2 C3];
plot(x,y,'g')
Compare my code with yours, side-by-side, and try to identify all the differences.
In particular, notice that I did not need to use for loops to calculate C2 and C3.
