小编Jus*_*tin的帖子

MATLAB:在时间序列中对NaN进行插值

问题:如何在小长度的NaNs上进行局部插值?

我有一个时间序列("x"数据在"t"次均匀采样)具有NaN块.例如:

x = [ 1   2   4    2 3 15 10 NaN NaN NaN NaN 2 4 NaN 19 25]
t = [0.1 0.2 0.3 ...etc..]
Run Code Online (Sandbox Code Playgroud)

我想在NaN上执行插值.

最基本的方法是从最左边的数据点到最右边的数据点进行线性插值.例如.从x = 10到x = 2的一条线,将从该线分配4个NaN值.

时间序列的长度约为150万,约为10000 NaN,因此我不想合并远离NaN位置的数据(插值).一些NaN的长度为1000-2000.

X(isnan(X)) = interp1(find(~isnan(X)), X(~isnan(X)), find(isnan(X)), 'linear'); 
Run Code Online (Sandbox Code Playgroud)

将使用整个时间序列在NaN上线性插值.

我如何在本地进行插值?线性应该足够了.也许线性插值在NaN块的左侧和右侧包含几个点(可能是100-200点).自然邻居或样条(?)算法可能更合适; 我必须小心不要在时间序列中添加异常行为(例如,为频率添加虚构的"功率"的插值).

更新:时间序列是一年中一分钟采样温度的记录.线性插值就足够了; 我只需填写~6-7小时的NaN长度间隙(我在NaN间隙之前和NaN间隙之后提供数据).

matlab interpolation time-series nan

7
推荐指数
2
解决办法
7524
查看次数

对临时字符串使用基于范围的循环时出现空字符?

当我使用基于范围的 for 循环遍历临时std::string(右值?)时,似乎有一个额外的字符,即 null 终止符\0

当字符串不是临时的(而是左值?)时,没有多余的字符。为什么?

    std::map<char, int> m;

    for (char c : "bar") m[c] = 0;

    for (auto [c, f] : m) {
        if (c == '\0') std::cout << "this is a null char, backward slash zero" << std::endl;
        std::cout << c << std::endl; 
    }
Run Code Online (Sandbox Code Playgroud)

输出:

this is a null char, backward slash zero

a
b
r
Run Code Online (Sandbox Code Playgroud)

\0(注意正在打印的空行)

相比:

    std::map<char,int> m;
    
    std::string s = "bar";
    
    for (char c : s) m[c] = 0;    
    
    for …
Run Code Online (Sandbox Code Playgroud)

c++ string c++11

3
推荐指数
1
解决办法
506
查看次数

标签 统计

c++ ×1

c++11 ×1

interpolation ×1

matlab ×1

nan ×1

string ×1

time-series ×1