sort and collect data
1 次查看(过去 30 天)
显示 更早的评论
Hi Guys, I have file that looks like this below (20 x 4) matrix. It consists of time, serial number, pessure and volume. I want to select the maximum value of pressure and the corresponding volume and time for each serial numbers every 4 secs all through the data. There are 4 items, serial number 1 represents the first, 2 the second, e.t.c. However the serial number 1 represents time where there is low/ no pressure as well. Could you help with this? Thanks
Time S/N Pressure Volume
00:00:01 1 20 2.4
00:00:02 1 25 2.5
00:00:03 1 30 2.6
00:00:04 1 35 2.7
00:00:05 1 0.3 2.8
00:00:06 1 1.4 2.9
00:00:07 2 20 3
00:00:08 2 30 3.1
00:00:09 2 40 3.2
00:00:10 2 50 3.3
00:00:11 1 0.6 3.4
00:00:12 1 1.5 3.5
00:00:13 3 20 3.6
00:00:14 3 30 3.7
00:00:15 3 40 3.8
00:00:16 3 50 3.9
00:00:17 1 0.1 4
00:00:18 1 2.3 4.1
00:00:19 4 20 4.2
00:00:20 4 30 4.3
00:00:21 4 34 4.4
00:00:22 4 50 4.5
00:00:23 1 0.3 4.6
00:00:24 1 4.1 4.7
2 个评论
Adam Danz
2019-8-6
Are there always 6 samples of each S/N and is S/N always in ascending order (except for the low pressure indicators)?
采纳的回答
Adam Danz
2019-8-6
编辑:Adam Danz
2019-8-7
Assuming you have 3 vectors named sn, pressure, and volume,
% Replace every 5th and 6th sn with 0
% * assumes that there will always be 4 samples of each SN
% followed by 2 low-pressure
sn(repmat(logical([0;0;0;0;1;1]),numel(sn)/6,1)) = 0;
% Identify groups of sn
[snGroupIdx, snGroup] = findgroups(sn);
% Calculate the max pressure within each group
maxPresSn = splitapply(@max,pressure,snGroupIdx);
% Find the volume that corresponds to the max pressure in each group
volumnSn = splitapply(@(x1,x2)x2(find(x1==max(x1),1)),pressure,volume,snGroupIdx);
% Put the results in a summary table
t = table(snGroup, maxPresSn, volumnSn, 'VariableNames', {'SN','MaxPres','Vol'});
Result
t = % FAKE DATA
5×3 table
SN MaxPres Vol
__ _______ ___
0 32 1
1 19 1
2 37 3
3 30 3
4 13 1
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Other Formats 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!