Need help with plotting a graph on matlab- linewidth

3 views (last 30 days)
I was wondering if someone could tell me why I get this error returning:
Error using plot
String argument is an unknown option.
Whenever I try to add the 'linewidth',2 parameter for the plot function.
Here's my code:
h1 = sin(x)+x^2/7-0.3;
g1 = cosh(0.2*x);
x_values = 0:.04:4;
y_values=subs(h1,x_values);
figure(2);clf reset
plot(x_values,y_values,'b:',x_values,subs(g1,x_values),'r');
title('Plot of two functions');
xlabel('x-axis');
ylabel('y-axis');
legend('Plot of h1','plot of g1')
The line specifically I need help with is:
plot(x_values,y_values,'b:',x_values,subs(g1,x_values),'r');
Adding in 'linewidth',2 here produces the error I mentioned before
plot(x_values,y_values,'b:','linewidth',2,x_values,subs(g1,x_values),'r');
Any help would be massively appreciated!

Accepted Answer

Thorsten
Thorsten on 14 Oct 2014
The help for plot states that
"The X,Y pairs, or X,Y,S triples, can be followed by
parameter/value pairs to specify additional properties
of the lines."
But this is not true if you have multiple x, y values in one plot command. In this case you have to split them like
plot(x_values,y_values,'b:','linewidth',2)
hold on
plot(x_values,subs(g1,x_values),'r');

More Answers (1)

Robert Cumming
Robert Cumming on 14 Oct 2014
If you split it over two plot commands it will work:
plot(x_values,y_values,'b:','linewidth',2)
plot(x_values,subs(g1,x_values),'r');
When passing in extra arguments - you cant then pass in other x, y pairs.

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!