Need help with plotting a graph on matlab- linewidth

6 ビュー (過去 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 件のコメント
Tom
Tom 2014 年 10 月 14 日
Thanks! got it working

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeDiscrete Data Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by