How to prevent overwrite the graph in looping?

7 views (last 30 days)
I want to have three eyediagrams and one graph combine three while loop together. The codes is something like the below:
N=2
while (N<=4)
. . . . . .
eyediagram(........)
if(N==2)
figure;
semilogy(........);
hold on;
semilogy(........);
elseif (N==3)
semilogy(........);
hold on;
semilogy(........);
else
semilogy(........);
hold on;
semilogy(........);
. . . . . . .
N=N+1;
end
  3 Comments
Alex Phang
Alex Phang on 8 Mar 2018
Is that possible do it in the while loop?

Sign in to comment.

Accepted Answer

Birdman
Birdman on 8 Mar 2018
Define figure and hold on just once before while loop. It would be more efficient:
N=2;
figure;hold on;
while (N<=4)
. . . . . .
eyediagram(........)
if(N==2)
semilogy(........);
semilogy(........);
elseif (N==3)
semilogy(........);
semilogy(........);
else
semilogy(........);
semilogy(........);
. . . . . . .
N=N+1;
end
  8 Comments
Alex Phang
Alex Phang on 11 Mar 2018
Save this in a file named as generate_PPM.m
function PPM=generate_PPM(M,nsym)
% function to generate PPM
% 'M' bit resolution
% 'nsym': number of PPM symbol
PPM=[];
for i= 1:nsym
temp=randint(1,M); % random binary number
dec_value=bi2de(temp,'left-msb'); % converting to decimal value
temp2=zeros(1,2^M); % zero sequence of length 2^M
temp2(dec_value+1)=1; % placing a pulse according to decimal value
% note that in matlab index does not start from zero, so need to add 1;
PPM=[PPM temp2]; % PPM symbol
end
end
Walter Roberson
Walter Roberson on 11 Mar 2018
You did not follow the structure I posted! When you follow the structure I posted, it works fine.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!