ind2sub is not working properly.
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 16 Ago 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
il 16 Ago 2017
Modificato: Stephen23
il 16 Ago 2017
Hadi Kasasbeh
il 16 Ago 2017
Modificato: Stephen23
il 16 Ago 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
il 16 Ago 2017
Modificato: Hadi Kasasbeh
il 16 Ago 2017
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
