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

KSSV
KSSV 2017년 4월 22일
Your while loop doesn't work..you are comparing two matrices packet and ndata. Check your code properly.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2017년 4월 22일

0 개 추천

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에 대해 자세히 알아보기

태그

질문:

2017년 4월 21일

답변:

2017년 4월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by