Matlab中的数据分析

Matlab中的数据分析,matlab,data-analysis,sampling,Matlab,Data Analysis,Sampling,我在Matlab中有一个时间向量,它没有一致的采样时间,例如,t=[0.1 0.2 0.3 0.4 0.5 0.7 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.9 3 3 3.1],当我绘制(t,a)时,我有另一个基于时间的向量,a=[2 5 2 4 5 7 8 0 10 1 0 25 6 14 5 2 7 98]有一条直线连接两个采样时间较大的点,如何消除采样时间不一致且跳到较大值的这些间隙?我知道在t和a中为相同的时间间隔定义0.7和1.3之间的NaN,以及2和2.9之间的N

我在Matlab中有一个时间向量,它没有一致的采样时间,例如,
t=[0.1 0.2 0.3 0.4 0.5 0.7 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.9 3 3 3.1]
,当我绘制(t,a)时,我有另一个基于时间的向量,
a=[2 5 2 4 5 7 8 0 10 1 0 25 6 14 5 2 7 98]
有一条直线连接两个采样时间较大的点,如何消除采样时间不一致且跳到较大值的这些间隙?我知道在
t
a
中为相同的时间间隔定义
0.7
1.3
之间的NaN,以及
2
2.9
之间的NaN可能会有所帮助,但如何区分采样时间是否发生变化呢?

也许您可以尝试以下代码,下面是两种方法:

  • 方法1:添加
    nan

  • 方法2:将向量除以区间

否,我不需要插值,在示例中,我需要在0.7和1.3之间以及2和2.9之间添加NaN,并在向量中对其执行相同的操作interval@FR我编辑了我的答案,所以你可以看看它是否也适合你
clc;
clear;
close all;

t = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.9 3 3.1]
a = [2 5 2 4 5 7 8 0 10 1 0 25 6 14 5 2 7 98]

dt = diff(t);
idx = find(dt > mode(dt));
tC = mat2cell(t',[idx(1),diff([idx,length(t)])]);
aC = mat2cell(a',[idx(1),diff([idx,length(t)])]);
nadd = dt(idx)/mode(dt);
T = [];
A = [];
for i = 1:length(nadd)
  T = [T; tC{i};ones(int32(nadd(i)),1)*nan];
  A = [A; aC{i};ones(int32(nadd(i)),1)*nan];
endfor
T = [T;tC{end}];
A = [A;aC{end}];

plot(T,A)
clc;
clear;

t = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.9 3 3.1]
a = [2 5 2 4 5 7 8 0 10 1 0 25 6 14 5 2 7 98]

dt = diff(t);
idx = find(dt > mode(dt));
tC = mat2cell(t',[idx(1),diff([idx,length(t)])]);
aC = mat2cell(a',[idx(1),diff([idx,length(t)])]);

hold on;
arrayfun(@(k) plot(tC{k},aC{k}),1:(length(idx)+1));