Not getting a finite answer

조회 수: 11 (최근 30일)
Chanaka Navarathna
Chanaka Navarathna 2019년 1월 27일
댓글: Walter Roberson 2019년 1월 27일
I am trying to excute following code and I am ending up getting infinity.
What I am trying to do is, compute signal to noise ratio for two different amplifications of M, 10 and 100. Final Signal 2 should include the contributions due to fluctuations of W, S and amplification factor (M). The output should be mean of final signal/standard deviation of final signal for M 10 and 100 separately. How do I separately obtain the data for M=10 and M=100?
W=1000; %Initial average excitation power
W1=W+rand(1,W)*10; %Power fluctuation
for M = [10 100] %Magnification factor
W2=W1*M;
end
for i=1:W2 %power fluctuation
end
S_i = 100; %Initial Signal
S=S_i+rand(1,S_i)*10; %Generate a set of multiple numbers for signal
for S_f=1:S %final signal
meanS=mean(S_f); %final signal 2
stdeviationS=std(S_f); %noise
SNRatio = mean(S_f)/std(S_f) %signal to noise ratio
end
  댓글 수: 6
Chanaka Navarathna
Chanaka Navarathna 2019년 1월 27일
What I am trying to do is calculate the mean/standard deviation ratio of Sf1 and Sf2 separetely for two different values of M (10 and 100). W and Si also has to change within the loop.
Walter Roberson
Walter Roberson 2019년 1월 27일
num_W1 = length(W1);
Mvals = [10 100]; %Magnification factor
num_M = length(Mvals);
W2 = zeros(num_M, num_W1);
for M_idx = 1 : num_M
M = Mvals(M_idx);
W2(M_idx, :) = W1*M;
end
The above follows a general pattern that you should learn. The values you use in Mvals can be computed or assigned arbitrarily or created randomly as is appropriate for the situation. You then loop an index over the number of them that you have, and use the index to determine where to store the result of the computation.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Statistics and Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by