for loop only shows value of last iteration.

4 visualizaciones (últimos 30 días)
Nawaf Al-Fraih
Nawaf Al-Fraih el 12 de Dic. de 2017
Editada: KL el 12 de Dic. de 2017
for SNR_db=0:10
N=((E)/(10^(SNR_db/10)));
r=((H*Q1)+N);
Ymf=transpose(H)*r;
Ymf_dec=pskdemod(Ymf,4);
Ymf_bi=de2bi(Ymf_dec,4);
Er=(b_bar-Ymf_bi);
end
for SNR_db=0:10 only shows the last iteration which is 10. i want every iteration value of this loop in order to compare them.

Respuestas (1)

KL
KL el 12 de Dic. de 2017
Editada: KL el 12 de Dic. de 2017
You're overwriting all your variables inside the loop so you'd only see the result of the last iteration. You'd need to use arrays to store output of each iteration.
%preallocate
N = zeros(1,11);
SNR_db=0:10;
%other variables as well
for k = 1:11
N(k)=((E)/(10^(SNR_db(k)/10)));
...
end
or use matlab wisely without a loop,
SNR_db = 0:10;
N=E./(10.^(SNR_db./10));
%and so on

Categorías

Más información sobre Link-Level Simulation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by