【发布时间】:2018-06-13 22:40:30
【问题描述】:
我有两个具有相同目的的文件,一个在 Python 中,一个在 MATLAB 中。读入数据文件后,我希望他们计算并出错,使用 detrend 删除恒定偏移量,然后使用 griddata 插入曲面以适应错误。
在消除 Python 文件中的数据趋势时,我尝试将 scipy.signal.detrend 与 linear 和 constant 参数类型一起使用,因为 constant 最初不起作用。 (See 用于 scipy.signal.detrend 的文档)
但是,这些方法都没有获得与 MATLAB 文件相同的数组 err,并且我确保在此之前的所有其他内容都匹配。你能告诉我另一种像 MATLAB 那样去趋势的方法吗?
Python 代码(减去标头/导入):
timestamp = datetime.datetime.today().strftime('%Y%m%d%H%M')
print timestamp
plt.rc('xtick', labelsize=5)
plt.rc('ytick', labelsize=5)
plt.rc('grid', ls='dotted')
plt.rcParams['lines.dotted_pattern'] = [0.1,0.5]
np.set_printoptions(suppress=True)
def main(argv):
testdir = argv[0] # if list indexing error --> you must input a file name after <python es15302_squareness.py> in the command line
fname = os.path.join(testdir,'OUTDATA.DAT')
s = np.loadtxt(fname) #If in current directory
s2 = np.transpose([s[:,0],s[:,2]]) # these are
s3 = np.transpose([-s[:,1],s[:,3]]) # all going
posEncUm = np.divide(s2,25000) # to be
posLasUm = np.divide(s3,25000) # 169x2
err = posEncUm - posLasUm;
# -------------------------Everything good up to here----------------------
err[:,0] = scipy.signal.detrend(err[:,0], type=='constant')
err[:,1] = scipy.signal.detrend(err[:,1], type=='constant')
print err
Matlab 代码:
function ES15302_squareness(myDir)
close all;
cd(myDir);
s = load('outdata.dat');
posEncUm = [s(:,1) s(:,3)]/25000;
posLasUm = [-s(:,2) s(:,4)]/25000;
err = posEncUm - posLasUm;
err(:,1) = detrend(err(:,1),'constant');
err(:,2) = detrend(err(:,2),'constant');
(我没有任何错误,只是 MATLAB 中的 err 在 detrends 后与 Python 中的 err 不匹配)
【问题讨论】:
-
请不要在代码中包含行号(无论如何你是怎么得到它们的);这使他们无法为我们复制粘贴。