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

4 ビュー (過去 30 日間)
Jason
Jason 2025 年 3 月 12 日
コメント済み: Jason 2025 年 3 月 12 日
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>
Jason
Jason 2025 年 3 月 12 日
Thankyou

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by