我有一个问题,我如何在矩阵内选择数据点进行绘图。我所拥有的是矩阵(1504 x 2),其中第一列是时间,第二列是测量。
许多测量值几乎与之前的测量值相同,因此我只想绘制与之前测量值相差至少0.1个单位的测量值。我知道我可以使用'diff'来获得测量的差异但是如何选择>的行(来自原始数据集)或=从先前的测量值到0.1?
我有
v= dataset;
v2= v(diff(v)<.1);
答案 0 :(得分:0)
获得与阈值相比的logical index差值:
v = [1 2 3 4 5 6 7 8; .5 .56 .57 .7 .9 .87 .6 .4].'; % data
th = .1; % threshold
indKeep = [true; abs(diff(v(:,2)))>=th]; % this assumes the first value is always kept
vPlot = v(indKeep,:); % apply as logical index into the rows of v
在示例中,
v =
1.000000000000000 0.500000000000000
2.000000000000000 0.560000000000000
3.000000000000000 0.570000000000000
4.000000000000000 0.700000000000000
5.000000000000000 0.900000000000000
6.000000000000000 0.870000000000000
7.000000000000000 0.600000000000000
8.000000000000000 0.400000000000000
vPlot =
1.000000000000000 0.500000000000000
4.000000000000000 0.700000000000000
5.000000000000000 0.900000000000000
7.000000000000000 0.600000000000000
8.000000000000000 0.400000000000000