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 个评论

Your while loop doesn't work..you are comparing two matrices packet and ndata. Check your code properly.

请先登录,再进行评论。

回答(1 个)

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;

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by