Why program shows Unrecognized function or variable 'g'.

5 ビュー (過去 30 日間)
Shuoze Xu
Shuoze Xu 2022 年 3 月 16 日
コメント済み: Shuoze Xu 2022 年 3 月 16 日
% legend() function
x = 0:0.5:4*pi;
y = sin(x);
h = cos(x);
w = 1./(1+exp(-x));
plot(x,y,'bd-',x,h,'g:',x,w,'ro-',x,g,'c^-');
legend('sinx','cos(x)','Sigmoid','Gaussn function');
% when i run program, it shows that Unrecognized function or variable 'g'.
% while there are g function on mathwork in Two-dimensional line plot module

採用された回答

Andreas Apostolatos
Andreas Apostolatos 2022 年 3 月 16 日
Hi,
In the following call of your code snippet,
plot(x,y,'bd-',x,h,'g:',x,w,'ro-',x,g,'c^-');
you are trying to plot variable 'g' against variable 'x' among other, but you never define variable 'g'. You can see this by typing the following command which reveals all variables existing in your Base Workspace,
whos
the output of which in your case is as follows,
Name Size Bytes Class Attributes
h 1x26 208 double
w 1x26 208 double
x 1x26 208 double
y 1x26 208 double
As you can see variable 'g' is nowhere to be seen.
I hope this helps.
Kind regards,
Andreas

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by