MATLAB: How to prevent overwrite the graph in looping

eyediagramsemilogy

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

Best Answer

  • 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