绘图功能不显示任何图形

时间:2014-12-28 15:40:47

标签: matlab signal-processing fft wavelet

我想要使用下面提到的代码实现的目的是,在一个图中绘制四个信号x1, x2, x3, x4,每个信号分别带有t1, t2, t3, t4。这样,每隔四分之一秒的新信号就会被绘制出不同的频率。但是,当我运行代码时,绘图只显示空图。

请告诉我代码中缺少的内容。

代码

% Time specifications:
Fs = 8000;                       % samples per second
dt = 1/Fs;                       % seconds per sample
StopTime = 1;                    % seconds
t = (0:dt:StopTime);         % seconds

t1 = (0:dt:.25);
t2 = (.25:dt:.50);
t3 = (.5:dt:.75);
t4 = (.75:dt:1);

x1 = (10)*cos(2*pi*3*t1);
x2 = (20)*cos(2*pi*6*t2);
x3 = (30)*cos(2*pi*10*t3);
x4 = (50)*cos(2*pi*15*t4);

% Plot the signal versus time:
figure;
xlabel('time (in seconds)');
ylabel('Amplitude');
title('Signal versus Time');
plot(t,x1,'r');
plot(t,x2,'g');
plot(t,x3,'b');
plot(t,x4,'black');

1 个答案:

答案 0 :(得分:1)

替换最后四行
hold on %// this prevents each subsequent `plot` from removing the previous graph
plot(t1,x1,'r'); %// use appropriate "t" vector: `t1` in this case
plot(t2,x2,'g');
plot(t3,x3,'b');
plot(t4,x4,'black');