Find index of value extracted from subset in larger set

2 ビュー (過去 30 日間)
DavidL88
DavidL88 2022 年 1 月 8 日
コメント済み: DavidL88 2022 年 1 月 8 日
I have a dataset in the form of a struct with two fields - each field is a double with 1,500 x 1 values. One field is t values, the other is p values. These are values are matched across rows. I want to find the minimum p value and then the corresponding t value within multiple subsets across these 1,000 values. For example, the minimum p value between rows 325:400 e.g. p value 0.04 in row 357 and the correspond t value which will then be in row 357 in the t values field. I can find the minimum p value within a subset (rows 325:400) but I don't know how to then get the index of this p value within the larger dataset so I can extract the corresponding t value. The below code gives me the index of the p value within the subset only i.e. row 32 (357-325=32) . I can try using find as below, but there are mutlple datapoints in the larger set that will match this p value. Is there a way to get the index within the larger dataset?
p = min(pvalue(325:400));
[idx1 idx2] = find(p == (pvalue));
t = tvalue(idx1)

採用された回答

Stephen23
Stephen23 2022 年 1 月 8 日
編集済み: Stephen23 2022 年 1 月 8 日
The simple MATLAB approach is to use indexing:
X = 325:400;
[p,Y] = min(pvalue(X));
t = tvalue(X(Y));

その他の回答 (1 件)

Voss
Voss 2022 年 1 月 8 日
start_row = 325;
end_row = 400;
[min_p,min_idx] = min(pvalue(start_row:end_row));
min_idx = min_idx+start_row-1;
t = tvalue(min_idx);

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by