how can I plot using the while loop

I am trying to generate a code that will plot(e,n) ; e=error and n= throughput efficacy . Any how I have written this code for now, but I can not check it because I can't see the value of n.
i=0;
bits=32;%length of bits in the packet
for e=0:0.05:0.5
packet=round(rand(1,bits));% to make sure the random numbers in the packet contain 1's or 0's in an array
ndata =bsc(packet,e);
totbits=bits;
cbits=bits;
n=cbits/totbits; %correct bits over total bits
while packet~=ndata
ndata =bsc(packet,e);
i=i+1;
j=abs(packet-ndata);
s=sum(j,2);
c=bits-s;
cbits=cbits+c;
totbits=totbits+bits;
n=cbits/totbits %correct bits over total bits
end
end
plot(e,n)
grid on
I need help, to know how can I see the value of n to compare it with the real value, to make sure my code is correct before i Plot. and secondly, how can i plot n for each e, since n will be different for each e.

1 comentario

KSSV
KSSV el 22 de Abr. de 2017
Your while loop doesn't work..you are comparing two matrices packet and ndata. Check your code properly.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 22 de Abr. de 2017
You'd need to index n inside the loop
n(i) = cbits/totbits
and recreate e before plotting
e = 0 : 0.05 : 0.5;
plot(e, n, 'b*-', 'LineWidth', 2);
grid on;

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 21 de Abr. de 2017

Respondida:

el 22 de Abr. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by