ind2sub is not working properly.
Show older comments
I have the following piece of code where ind2sub is not working properly because when I plot the function PeLRTfusion in 3D, the results are not compatible. I want to find the coordinates of minimum value of PeLRTfusion. Also, when I use the resulted coordinates again in PeLRTfusion, the value of PeLRTfusion is different than the resulted min value from the code.
MuX1=1;
MuX2=2;
SigmaX1=1;
SigmaX2=0.5;
PH1=0.6;
PH0=1-PH1;
const=6;%A constant for how many sigmas away from the mean the program should go.
step=0.1;%To control the accuracy of the results.
Lower=-const*max(SigmaX1,SigmaX2);
Upper=const*max(SigmaX1,SigmaX2)+max(MuX1,MuX2);
LamdaSearchRange=Lower:step:Upper;
%Pe using the LRT fusion rule.
fun=@(Lamda1,Lamda2) PeLRTfusion(PH1,SigmaX1,SigmaX2,MuX1,MuX2,Lamda1,Lamda2);
PeOfLRT=bsxfun(fun,LamdaSearchRange,LamdaSearchRange');
[MinPeOfLRTval, MinIdx] = min(PeOfLRT(:));
MinPeOfLRTval
[MinLamda1Index, MinLamda2Index] = ind2sub(size(PeOfLRT),MinIdx);
MinLamda1=LamdaSearchRange(MinLamda1Index)
MinLamda2=LamdaSearchRange(MinLamda2Index)
Any help is really appreciated. Thank you.
5 Comments
Image Analyst
on 16 Aug 2017
Since I can't test it because you forgot to include PeLRTfusion, I gave up trying to help. Include PeLRTfusion if you want people to be able to run your code and fix it.
Hadi Kasasbeh
on 16 Aug 2017
Edited: Stephen23
on 16 Aug 2017
Hadi Kasasbeh
on 16 Aug 2017
Edited: Stephen23
on 16 Aug 2017
ind2sub seems to be working perfectly:
[MinPeOfLRTval, MinIdx] = min(PeOfLRT(:))
MinPeOfLRTval =
-1.6092e+042
MinIdx =
4018
>> val = PeOfLRT(MinLamda1Index,MinLamda2Index)
val =
-1.6092e+042
>> MinPeOfLRTval - val
ans =
0
Hadi Kasasbeh
on 16 Aug 2017
Edited: Hadi Kasasbeh
on 16 Aug 2017
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!