Reputation: 3
I want to plot a line, that before the number a the line would be dashed and after the number a the line would be solid in matlab, for example,
clear all;close all;
x=0:.01:.5;
z=.51:.01:1;
f=x.^2-3*x+.5;
g=z.^2-3*z+.5;
plot(x,f,'--',z,g,'b')
Is there a way to do this without spliting the interval and creating two functions?
Upvotes: 0
Views: 816
Reputation: 13610
You can make things a little more automated than your example like this:
clear all;close all;
x=0:.01:1;
f=x.^2-3*x+.5;
a = 0.5;
hold on
plot(x(x<a),f((x<a)),'--')
plot(x(x>=a),f(x>=a),'b-')
Upvotes: 4
Reputation: 409
MATLAB does not have options for plotting multiple styles for the same function.
The best place to see the options is help plot
You can refer to the help page here.
Upvotes: 0