Find index of value extracted from subset in larger set
2 ビュー (過去 30 日間)
古いコメントを表示
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)
0 件のコメント
採用された回答
その他の回答 (1 件)
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 Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!