sort and collect data

4 views (last 30 days)
Olu B
Olu B on 6 Aug 2019
Commented: Adam Danz on 8 Aug 2019
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 Comments
Adam Danz
Adam Danz on 6 Aug 2019
Are there always 6 samples of each S/N and is S/N always in ascending order (except for the low pressure indicators)?
Olu B
Olu B on 6 Aug 2019
There are always 4 samples of each S/N that represents every 4 seconds and the S/N is always in ascending order except for the low pressure indicators that represents 2 secs of low/no pressure, that is why I have more 1's showing up than other S/N. The program is suppose to take measurement every 4 secs and 2 secs no measurement so as to differentiate the 4 S/N however when there is no/low pressure for those 2 secs time step it is being logged as S/N 1

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 6 Aug 2019
Edited: Adam Danz on 7 Aug 2019
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
  2 Comments
Olu B
Olu B on 8 Aug 2019
Thanks Adam.
Adam Danz
Adam Danz on 8 Aug 2019
Glad I could help!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!