範囲を指定して最大値を求める方法
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
匡彬 高橋
am 18 Jan. 2023
Kommentiert: 匡彬 高橋
am 24 Jan. 2023
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 Kommentare
Akzeptierte Antwort
交感神経優位なあかべぇ
am 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, :) % 検索した行の抽出
Weitere Antworten (1)
Hernia Baby
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu 動的システム モデル finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!