Need help with plotting a graph on matlab- linewidth

3 次查看(过去 30 天)
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!

采纳的回答

Thorsten
Thorsten 2014-10-14
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');

更多回答(1 个)

Robert Cumming
Robert Cumming 2014-10-14
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.

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by