Find index of value extracted from subset in larger set

5 次查看(过去 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)

采纳的回答

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 CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by