Creating new data where each new row is the minimum (of 2nd column) of each 2 rows.

5 次查看(过去 30 天)
Hello, I have the following data and I want to create a new set such that for each 2 rows of data, the row is taken with the lowest value in col 2.
i.e. it would begin like this:
1 61 % min of rows 1 & 2
2 57 % min of rows 3 & 4
3 56 % min of rows 5 & 6
4 79 % min of rows 7 & 8
1.00 61.00
2.00 62.00
3.00 60.00
4.00 57.00
5.00 56.00
6.00 60.00
7.00 79.00
8.00 82.00
9.00 55.00
10.00 55.00
11.00 54.00
12.00 53.00
13.00 53.00
14.00 53.00
15.00 62.00
16.00 57.00
17.00 72.00
18.00 58.00
19.00 83.00
20.00 73.00
21.00 102.00
22.00 77.00
23.00 107.00
24.00 111.00
25.00 NaN
26.00 NaN
27.00 NaN
28.00 NaN
28.00 0.20

采纳的回答

Jason
Jason 2025-3-12
编辑:Jason 2025-3-12
Seems like this works (had to delete last row from data)
B = reshape(y,[2,10]) % Each column is a pair of row data
C=min(B) % default is min of each column
How to catch the case where there is an extra row, i.e. how to ignore it
  2 个评论
Cris LaPierre
Cris LaPierre 2025-3-12
Only reshape an even number of rows.
y = [61 62 60 57 56 60 79 82 55 55 54 53 53 53 62 57 72 58 83 73 102 77 107 111 NaN NaN NaN NaN 0.2];
r = 2*floor(length(y)/2);
B = reshape(y(1:r),2,[]) % Each column is a pair of row data
B = 2×14
61 60 56 79 55 54 53 62 72 83 102 107 NaN NaN 62 57 60 82 55 53 53 57 58 73 77 111 NaN NaN
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
C=min(B)
C = 1×14
61 57 56 79 55 53 53 57 58 73 77 107 NaN NaN
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by