Finding position of a multidimensional array given manual value

Hello,
I have the following:
[max_val, position] = max(sh(:)); %Gets max value of sh and provides position
[yAxInd,yCxInd,yVxInd] = ind2sub(size(sh),position); % Given position it provides me with the multidemnsional parameters
--------------
Is there any way i can provide the value myself to then get the parameters? Something like this..
[position] = [MyInput]; % User looking for position of a particular value
[yAxInd,yCxInd,yVxInd] = ind2sub(size(sh),position); %Given position it provides me with the multidemnsional parameters
Thanks! Appreciate the help!

 採用された回答

Matt J
Matt J 2021 年 12 月 19 日
編集済み: Matt J 2021 年 12 月 19 日

0 投票

Your question is a little unclear to me, but I think you mean this:
[yAxInd,yCxInd,yVxInd] = ind2sub(size(sh),find(sh==value))

4 件のコメント

IDN
IDN 2021 年 12 月 19 日
Hi Matt! Thanks for taking the time to help me out.
What i mean is that i can use the below to provide me with the "Y,C,V" values given the position of the Max value of "sh"
[max_val, position] = max(sh(:)); %Gets max value of sh and provides position
[yAxInd,yCxInd,yVxInd] = ind2sub(size(sh),position);
But what if i know already the Max value of "sh", how can i just provide the value of "sh" to either get its position in the multidimensional array or to get the "Y,C,V" values.
Your suggestion above doesnt work. Thanks!
Matt J
Matt J 2021 年 12 月 19 日
編集済み: Matt J 2021 年 12 月 19 日
Your suggestion above doesnt work.
Doesn't it? It seems to in the following example.
sh=randi(100,3,3,3)
sh =
sh(:,:,1) = 22 90 69 37 69 70 19 75 77 sh(:,:,2) = 13 28 30 86 95 9 51 31 84 sh(:,:,3) = 99 30 53 10 48 56 3 92 29
value=max(sh(:)); %"i know already the Max value of sh"
[yAxInd,yCxInd,yVxInd] = ind2sub(size(sh),find(sh==value))
yAxInd = 1
yCxInd = 1
yVxInd = 3
IDN
IDN 2021 年 12 月 20 日
I see, it does work, the only issue i think am having is that there are alot of result matching the value so it creates a matrix 0x1 double and i am not able to see the values...any input? Thanks!
Matt J
Matt J 2021 年 12 月 20 日
It is of course possible that there may be no matches or many. The code has succeeded in either case.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

リリース

R2020a

質問済み:

IDN
2021 年 12 月 19 日

コメント済み:

2021 年 12 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by