开发者

Error in the for loop in matlab

I try to plot from for loop and I succeed in it(in small program) but when i try with a larger program, I get the f开发者_开发技巧ollowing error: "{Error using ==> semilogy Not enough input arguments. Error in ==> test6 at 27 semilogy(pe1,'b',pe2,'r');} and i dont why I wish someone can have a look and help me

my code is

clc;
clear;
for n=0:45;

    n=n+1;
   q=55;
    w=42;
    r=-228.6;
    y(n+1)=n+34+w-q-r;
end 

b=36;
o=0.2;
x=b/(1+o);                        % RB for Bpsk
k=2*b/(1+o);                      % Rb for Qpsk
z=y-x;                            % Eb/No for Bpsk
m=y-k;                            % Eb/No for Qpsk
g=0; 
s=0;  
pe1= zeros(1, 47);
pe2= zeros(1, 47);

for i=0:45; 
    g=10.^(0.1*z);
    pe1=0.5*erfc(sqrt(g));
    s=10.^(0.1*m);
    pe2=0.5*erfc(sqrt(s));
end

semilogy(pe1,'b',pe2,'r');
xlabel('energy per bit per noise power spectral density (Eb/No) (dB) ');
ylabel('Bit error rate (Pe)');
legend('Bpsk','Qpsk');
grid;


The problem causing your error is that semilogy (like plot) expects inputs in the form semilogy(X1,Y1,'b',X2,Y2,'r') if you want to plot more than one line at the same time. So, your semilogy should be semilogy(z,pe1,'b',m,pe2,'r'). You also need the z and m in the semilogy call to get your x-axis scale correct.

You have a few other problems. I have not made it look exactly like I'd do it, since I wanted your code to be recognizable to you. But you may wish to compare your code line by line to the following. One thing I've done that is probably wrong is change r to its negative since otherwise y is far to large (so pe1 and pe2 were zero, via erfc).

Your code was already vectorized, so I got rid of the for loops. Note that you wouldn't have n=n+1 in a for n= loop; it's incremented automatically.

clc;
clear;
n=0:45;
q=55;
w=42;
r=228.6;
y=n+34+w-q-r;

b=36;
o=0.2;
x=b/(1+o);                        % RB for Bpsk
k=2*b/(1+o);                      % Rb for Qpsk
z=y-x;                            % Eb/No for Bpsk
m=y-k;                            % Eb/No for Qpsk

g=10.^(0.1*z);
pe1=0.5*erfc(sqrt(g));
s=10.^(0.1*m);
pe2=0.5*erfc(sqrt(s));

semilogy(z,pe1,'b',m,pe2,'r');
xlabel('energy per bit per noise power spectral density (Eb/No) (dB) ');
ylabel('Bit error rate (Pe)');
legend('Bpsk','Qpsk');
grid;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜