フィルターのクリア

Find value in an NxMxP array and return index

3 ビュー (過去 30 日間)
Nasser Ramsis
Nasser Ramsis 2017 年 1 月 5 日
編集済み: Stephen23 2017 年 1 月 5 日
I have an N x M x P array. Its filled with all possible values of a parameter. I'm looking for the value closest to a target I have. I need to find that value and the index of said value.
I've played around with these functions but they don't work the way I want them.
[C, I] = min(min(min(abs(theta-targettheta))));
thetafound=abs(targettheta-C);
this only return the p index not the n or m
[C, I]=min(abs(theta-targettheta),[],3);
this isn't returning just 1 result or the array even.
Any ideas?

回答 (1 件)

Stephen23
Stephen23 2017 年 1 月 5 日
編集済み: Stephen23 2017 年 1 月 5 日
>> val = 9;
>> X = reshape(1:36,3,3,4) + rand(3,3,4);
>> [C,I] = min(abs(X(:)-val));
>> X(I)
ans = 9.3895
Or with a different value:
>> val = 24;
>> [C,I] = min(abs(X(:)-val));
>> X(I)
ans = 23.642
Note that min returns the linear index, not a subscript index.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by