Clear Filters
Clear Filters

Pe versus the signal amplitude A

4 views (last 30 days)
reem
reem on 9 Apr 2011
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');

Accepted Answer

Matt Fig
Matt Fig on 9 Apr 2011
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 Comment
reem
reem on 9 Apr 2011
Thank you so much Matt,you help me in everything,you are the best
teacher for me,you have a great soul
Thank you

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!