範囲を指定して最大値を求める方法
68 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
2列の行列から、1列目において範囲を指定し、2列目の最大値とその時の1列目を求めたいのです。
例:
1 13
2 115
3 14
4 21
5 42
6 63
7 413
8 100
9 734
上のような2列9行の行列から、1列目で2から7までの範囲を指定し、"最大値413, その時の1列目は7"となるように求めたいです。
3 commentaires
Réponse acceptée
交感神経優位なあかべぇ
le 18 Jan 2023
該当するデータを抽出する例を記述しました。
A = [1 13;2 115;3 14;4 21;5 42;6 63;7 413;8 100;9 734] % 例のデータ作成
btwn2_7Idx = A(:,1) >= 2 & A(:,1) <=7; % 1列目の2から7までの範囲を指定
B = A(btwn2_7Idx, :); % 指定した行の抽出
[~, maxIdx] = max(B(:,2)); % 2列目が最大値の行番号の検索
maxRow = B(maxIdx, :) % 検索した行の抽出
Plus de réponses (1)
Hernia Baby
le 21 Jan 2023
まずはデータを作成します
data = [1 13
2 115
3 14
4 21
5 42
6 63
7 413
8 100
9 734];
もし1列目が行番号なら以下のようにできます
data2 = data(2:7,2);
max_num = max(data2);
idx = data(:,2) == max_num
fprintf('2~7行目での最大値は%i(%i行目)',data(idx,2),data(idx,1))
0 commentaires
Voir également
Catégories
En savoir plus sur 記述統計 dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!