我想在matlab的一个表中获得每组排名前两位和后两位的观测结果。我没有可用的组过滤器功能。
我有一张这样的桌子:
MeasurementTime = datetime({'2015-12-18 08:03:05';'2015-12-18 10:03:17';'2015-12-18 12:03:13'});
VAR1 = [37.3;39.1;42.3];
VAR2 = [30.1;30.03;29.9];
VAR3 = [13.4;6.5;7.3];
VAR4 = [3.4;1.5;0.3];
VAR5 = [3.9;1.1;0.2];
TT = timetable(MeasurementTime,VAR1, VAR2, VAR3, VAR4, VAR5)
TT1 = stack(TT, {'VAR1','VAR2','VAR3','VAR4','VAR5'},'NewDataVariableName','Value','IndexVariableName','Group')
MeasurementTime Group Value
____________________ _____ _____
18-Dec-2015 08:03:05 VAR1 37.3
18-Dec-2015 08:03:05 VAR2 30.1
18-Dec-2015 08:03:05 VAR3 13.4
18-Dec-2015 08:03:05 VAR4 3.4
18-Dec-2015 08:03:05 VAR5 3.9
18-Dec-2015 10:03:17 VAR1 39.1
18-Dec-2015 10:03:17 VAR2 30.03
18-Dec-2015 10:03:17 VAR3 6.5
18-Dec-2015 10:03:17 VAR4 1.5
18-Dec-2015 10:03:17 VAR5 1.1
18-Dec-2015 12:03:13 VAR1 42.3
18-Dec-2015 12:03:13 VAR2 29.9
18-Dec-2015 12:03:13 VAR3 7.3
18-Dec-2015 12:03:13 VAR4 0.3
18-Dec-2015 12:03:13 VAR5 0.2
该组是MeasurementTime。理想情况下,我希望这是前2个观察结果:
MeasurementTime Group Value
____________________ _____ _____
18-Dec-2015 08:03:05 VAR1 37.3
18-Dec-2015 08:03:05 VAR2 30.1
18-Dec-2015 10:03:17 VAR1 39.1
18-Dec-2015 10:03:17 VAR2 30.03
18-Dec-2015 12:03:13 VAR1 42.3
18-Dec-2015 12:03:13 VAR2 29.9
对于底部2个观测值:
MeasurementTime Group Value
____________________ _____ _____
18-Dec-2015 08:03:05 VAR4 3.4
18-Dec-2015 08:03:05 VAR5 3.9
18-Dec-2015 10:03:17 VAR4 1.5
18-Dec-2015 10:03:17 VAR5 1.1
18-Dec-2015 12:03:13 VAR4 0.3
18-Dec-2015 12:03:13 VAR5 0.2
有什么想法吗?
我不确定你说的"前2个观察结果";以及";底部2个观察值";,不幸的是,我不能发表评论,所以我将尝试将您想要的输出复制为:
TTtop2 = stack(TT(:,1:2),{'VAR1','VAR2'},'NewDataVariableName','Value','IndexVariableName','Group')
TTbottom2 = stack(TT(:,4:5),{'VAR4','VAR5'},'NewDataVariableName','Value','IndexVariableName','Group')