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
Python Scipy detrend不等同于MATLAB_Python_Matlab_Scipy - Fatal编程技术网

Python Scipy detrend不等同于MATLAB

Python Scipy detrend不等同于MATLAB,python,matlab,scipy,Python,Matlab,Scipy,我有两个相同用途的文件,一个在Python中,一个在MATLAB中。读入数据文件后,我希望他们计算并更正错误,使用detrend删除常量偏移,然后使用griddata插值曲面以拟合错误 在删除Python文件中的数据趋势时,我尝试将scipy.signal.detrend与linear和constant参数类型一起使用,因为constant最初不起作用。(用于scipy.signal.detrend的文档) 但是,这两种方法都没有得到与MATLAB文件相同的数组err,我确保到那时为止所有其他方

我有两个相同用途的文件,一个在Python中,一个在MATLAB中。读入数据文件后,我希望他们计算并更正错误,使用detrend删除常量偏移,然后使用griddata插值曲面以拟合错误

在删除Python文件中的数据趋势时,我尝试将
scipy.signal.detrend
linear
constant
参数类型一起使用,因为
constant
最初不起作用。(用于
scipy.signal.detrend
的文档)

但是,这两种方法都没有得到与MATLAB文件相同的数组
err
,我确保到那时为止所有其他方法都匹配。你能告诉我一种与MATLAB不同的detrend方法吗

Python代码(减去标题/导入):


(我没有任何错误,只是MATLAB中的err与Python中的err在detrends之后不匹配)

我不确定是否有不同的
scipy
/
matplotlib
函数来解决这个问题,但同时,通过计算MATLAB文件中每列的平均值,平均值接近于0(在0.0001范围内)我想我只需取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
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');