Need help with plotting a graph on matlab- linewidth

조회 수: 4 (최근 30일)
Tom
Tom 2014년 10월 14일
댓글: Tom 2014년 10월 14일
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에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by