Is this code ok?It asked to plot function together with hold on...syms x y; t=-2:0.1:2 n=-2:0.1:2 x=2*sin(4*pi*t); y=2*sin(4*pi*n); plot(t,x,'r',n,y,'g'); hold on; title('function'); legend('x function', 'y function'); grid on;

Is this code ok?It asked to plot function together with hold on. But when I run code,I have just y function ?
syms x y;
t=-2:0.1:2
n=-2:0.1:2
x=2*sin(4*pi*t);
y=2*sin(4*pi*n);
plot(t,x,'r',n,y,'g');
hold on;
title('function');
legend('x function', 'y function');
grid on;

回答(2 个)

You only get one plot line because your "t" and "n" are the same, and you apply the same formula to each of them, so the results are identical.

类别

在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息

提问:

2013-4-23

Community Treasure Hunt

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

Start Hunting!

Translated by