Not getting a finite answer
Show older comments
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 Comments
Walter Roberson
on 27 Jan 2019
for S_f=1:S %final signal
meanS=mean(S_f); %final signal 2
stdeviationS=std(S_f); %noise
Your for loop is over the integers 1:S. At each step you are taking the mean of the scalar integer loop variable, and the standard deviation of that scalar integer loop variable. The standard deviation of a scalar is always 0. The ratio of a positive value to 0 is infinite.
You are also overwriting outputs in each iteration of your first and third loops. Your second loop does nothing.
Chanaka Navarathna
on 27 Jan 2019
Walter Roberson
on 27 Jan 2019
Sorry II cannot figure out the intent of the code based upon what is posted.
for ss = 1:whatever
result(ss) = calculted value
end
Chanaka Navarathna
on 27 Jan 2019
Chanaka Navarathna
on 27 Jan 2019
Walter Roberson
on 27 Jan 2019
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.
Answers (0)
Categories
Find more on Statistics and Linear Algebra 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!