# 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;

조회 수: 1(최근 30일)
nickey 2013년 4월 23일
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개)

Walter Roberson 2013년 4월 23일
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.
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

bym 2013년 4월 23일
• no need for syms x y
• x & y are the same thing
perhaps you meant
y = 2*cos(4*pi*t)

댓글을 달려면 로그인하십시오.

### 범주

Find more on Common Operations in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!