Not getting a finite answer
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 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.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!