sort and collect data

조회 수: 1 (최근 30일)
Olu B
Olu B 2019년 8월 6일
댓글: Adam Danz 2019년 8월 8일
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
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)?
Olu B
Olu B 2019년 8월 6일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
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
  댓글 수: 2
Olu B
Olu B 2019년 8월 8일
Thanks Adam.
Adam Danz
Adam Danz 2019년 8월 8일
Glad I could help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Other Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by