Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么更改时间会对MATLAB中的输出图形产生相反的影响?_Matlab_Plot_Sampling_Subplot - Fatal编程技术网

为什么更改时间会对MATLAB中的输出图形产生相反的影响?

为什么更改时间会对MATLAB中的输出图形产生相反的影响?,matlab,plot,sampling,subplot,Matlab,Plot,Sampling,Subplot,这是我的密码: clear all; %% Load the earthquake data file load ECE350_Earthquake_Demo.mat tearth = 0:dt:(length(d)-1)*dt; t1 = tearth'; %% Play the sound of the earthquake sound(d, fs) figure,subplot(3, 1, 1); % 3 subplots in a 3x1 matrix plot(t1,d) %% plo

这是我的密码:

clear all;
%% Load the earthquake data file
load ECE350_Earthquake_Demo.mat
tearth = 0:dt:(length(d)-1)*dt;
t1 = tearth';
%% Play the sound of the earthquake
sound(d, fs)
figure,subplot(3, 1, 1); % 3 subplots in a 3x1 matrix
plot(t1,d) %% plots f(t)
title('First Subplot f(t)')

subplot(3, 1, 2);
plot(t1*2, d) %% plots f(2t)
title('Second Subplot f(2t)')

subplot(3, 1, 3);
plot(t1*(1/2), d) %% plots f(t/2)
title('Third Subplot f(t/2)')

xlim([0 20]);
orient landscape
delete 'Demo_plot1.pdf'
print -dpdf 'Demo_plot1'
此代码加载到地震数据文件中,并将输出绘制到图形上

我将垂直绘制三个不同的子图,并分别绘制f(t)、f(2t)和f(t/2)

自然地,f(2t)应该压缩图,f(t/2)应该展开图。 我的代码做相反的事情——f(2t)压缩,f(t/2)扩展(t1*2和t1/2是我实现这一点的方式)

输出格式很好,一切正常。这两个图只是切换


这是为什么?

这里有一个清晰的方法可以看出
f(2t)
确实在MATLAB中压缩函数,就像您认为的那样:

t = 0:.1:2*pi;
figure
hold on
plot(t, sin(t))
plot(t, sin(2*t))
plot(t, sin(t/2))
legend({'sin(t)', 'sin(2t)', 'sin(t/2)'})
在我的示例中,这非常有效,因为
sin
是连续的:它可以将
t
的任何值作为输入。在你的例子中,事情有点复杂,因为
d
是离散的:有
d(1)
d(2)
,…,但没有
d(.5)

如果你“只想看到正确的图”,让我们把
d
看作是连续函数
f
的样本,例如
d(n)=f(dt*n)
表示整数
n
。然后,对于绘图,选择
t
s,这样您就不再需要
f
的值:

t2 = t1 * 2;
plot(t2, d)
绘制f(t/2),因为当我们绘制
i
th点时,t值是
t2(i)
=
t1(i)*2
,f(t)值是
d(i)
=
f(dt*i)
=
f(t1(i))


绘制f(t*2)因为当我们绘制
i
th点时,t值是
t3(i)
=
t1(i)/2
,f(t)值是
d(i)
=
f(dt*i)
=
f(t1(i))
绘制(t*2,d)
不绘制
f(2*t)
。想象一下
t=[12345]
,那么
图(t,d)
将有x坐标1,2,3,4和5<代码>绘图(t*2,d)会有x坐标2,4,6,8,10,所以看起来是伸展的。这就是我认为它可能会做的。这是我能想到的实现这一目标的唯一方法。当我声明变量时,我是否需要对它进行一些更改?与其在子图中更改它,不如用与您一直在做的相反的方式来做,即
f(2*t)
plot(t1/2,d)
,反之亦然。这不只是强迫它看起来像我想要的吗?这会给我f(2t)和f(t/2)的真实图形吗?是的,这是正确的。
t3 = t1 / 2;
plot(t3, d)