Avoid infinity in the answer

15 ビュー (過去 30 日間)
Chanaka Navarathna
Chanaka Navarathna 2019 年 2 月 9 日
コメント済み: Chanaka Navarathna 2019 年 2 月 11 日
Hi,
I am trying to run this code and, I always get infinity for my first iteration. Is there a way to avoid that? or at least filter that answers which gives infinity.
for i=1:M %for loop for M repetitions
Nx=N+randn(1,M)*CN; %excitation photon fluctuation
Nt=Nx*10.^-(E*C*l); %Nt = transmitted photons
SD2=sqrt(Nt); %This relationship is only valid for a Poisson distribution.
Nt1=Nt+randn(1,1)*SD2; %Nt = transmitted photon fluctuation
Nt2=mean(Nt1)+sqrt(Nt1)*randn(1,1); %detected photon fluctuation
A(i)=-log(Nt2/Nx); %calculation of absorbance
meanA=mean(A); %mean absorbance signal
standdeviationA=std(A); %noise
SNRUV(i)=meanA/standdeviationA %1/RSD=Signal to noise ratio for absorbance
end
  4 件のコメント
Star Strider
Star Strider 2019 年 2 月 9 日
Reiterating:
What are the variable values (‘M’,‘CN’,‘E’), etc.?
Knowing the relevant function arguments is important. We could make wild guesses for them and never come close to the expected values for them.
Chanaka Navarathna
Chanaka Navarathna 2019 年 2 月 9 日
N,E,C,Q,f,l,CN,M = 1000000,10000,10*10^-6,0.6,0.01,1,1000, 10 respectively

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

採用された回答

John D'Errico
John D'Errico 2019 年 2 月 9 日
編集済み: John D'Errico 2019 年 2 月 9 日
Sorry. I had a typo in what I entered before.
The first time through the loop. what do you expect?
A is a scalar on the first time throguh. What is the standard deviationm of a scalar variable? ZERO.
Then you divide by that standard deviation, so you get inf. Only you know what it is that you SHOULD do in that case.
  1 件のコメント
Chanaka Navarathna
Chanaka Navarathna 2019 年 2 月 11 日
Took the SNR calculation out from the loop and it was resolved. Thank you.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by