我刚刚在工作,虽然转换了一些MATLAB脚本在R中工作,但是从未在我的生活中使用MATLAB,并且不完全是R上的专家。我遇到了一些麻烦。
编辑:这是我设计的一个脚本,用于纠正绝缘质量效应产生的滞后温度测量。我的理解是,它会查看温度的变化率,并尝试调整传感器响应时间产生的误差。不幸的是,我没有任何文献可以让我指出我期望从函数中得到的数字,唯一能找到的方法是在稍后的日期进行实验性测试。
原文:
function [Tc, dT] = CTD_TempTimelagCorrection(T0,Tau,t)
N1 = Tau/t;
Tc = T0;
N = 3;
for j=ceil(N/2):numel(T0)-ceil(N/2)
A = nan(N,1);
# Compute weights
for k=1:N
A(k) = (1/N) + N1 * ((12*k - (6*(N+1))) / (N*(N^2 - 1)));
end
A = A./sum(A);
# Verify unity
if sum(A) ~= 1
disp('Error: Sum of weights is not unity');
end
Comp = nan(N,1);
# Compute components
for k=1:N
Comp(k) = A(k)*T0(j - (ceil(N/2)) + k);
end
Tc(j) = sum(Comp);
dT = Tc - T0;
end我设法达到的地方:
CTD_TempTimelagCorrection
## Define which equation to use based on duration of lag and frequency
## With ESM2 profiler sampling @ 2hz: N1>tau/t = TRUE
N1 = Tau/t
Tc = temp
N = 3
for(i in ceiling(N/2):length(temp)-ceiling(N/2)){
A = matrix(nrow=N,ncol=1)
# Compute weights
for(k in 1:N){
A[k] = (1/N) + N1 * ((12*k - (6*(N+1))) / (N*(N^2 - 1)))
}
A = A/sum(A)
# Verify unity
if(sum(A) != 1){
print("Error: Sum of weights is not unity")
}
Comp = matrix(nrow=N,ncol=1)
# Compute components
for(k in 1:N){
Comp[k] = A[k]*temp[i - (ceiling(N/2)) + k]
}
Tc[i] = sum(Comp)
dT = Tc - temp
}
return(dT)
}我认为问题是Comp [k]行,有人能指出我做错了什么吗?我不确定我能否以这种方式选择数组的元素。
顺便提一下,Tau = 1,t = 0.5,temp(或T0)将是一个向量。
谢谢
编辑:显然,我的描述在解释我的代码示例时过于简短,我不确定我能写的更多内容是否相关,而不仅仅是浪费人们的时间。这是否足够先生过滤器?