Pe versus the signal amplitude A

조회 수: 1 (최근 30일)
reem
reem 2011년 4월 9일
Hello everybody
I want to know,what is the problem in my program,when I run the
program,nothing appear in my graph only coordinates x and y.
please I want to know, what is the problem here
can anyone help me and I will not forget any help forever
this is my program
A= [0.1:0.1:5];
for k=1:length(A)
error=0;
for i=1:1000
w=randn(1,1)
if (A(k)/2+w)<=0
error=error+1;
end
end
P(k,1)= (error/100);
end
semilogy(length(A),P(k,1),'b.-');
hold on
grid on
legend('Psk');
xlabel('the signal amplitude A');
ylabel('probability of error');
title('Pe versus the signal amplitude A');

채택된 답변

Matt Fig
Matt Fig 2011년 4월 9일
Did you mean to plot:
semilogy(A.',P,'b.-');
Also, I would recommend you not name your variables the same name as MATLAB functions. You have a variable named 'error' and one named 'i'. Both of these variables mask the MATLAB functions of the same name. So if you run your code then try to use the MATLAB function, you will get either an error or a strange result.
In addition, if you need to build an array in a FOR loop, the best practice is to pre-allocate the array so that your code runs efficiently. In your case:
P = zeros(size(A));
Here is the code with pre-allocation and other changes to avoid masking.
A = 0.1:0.1:5;
P = zeros(size(A)); % Pre-allocation!
for k = 1:length(A)
err = 0;
for m = 1:1000
w = randn(1,1);
if (A(k)/2+w)<=0
err = err+1;
end
end
P(k) = (err/100);
end
semilogy(A,P,'b.-');
hold on
grid on
legend('Psk');
xlabel('the signal amplitude A');
ylabel('probability of error');
title('Pe versus the signal amplitude A');
.
.
EDIT
.
.
Your FOR loop can be simplified to (at least) the following, which is still readable.
for k = 1:length(A)
P(k) = sum((A(k)/2 + randn(1,1000))<=0)/100;
end
  댓글 수: 1
reem
reem 2011년 4월 9일
Thank you so much Matt,you help me in everything,you are the best
teacher for me,you have a great soul
Thank you

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by