matlab中for循环出错
我尝试从 for 循环中进行绘制,并且成功了(在小程序中),但是当我尝试使用更大的程序时,出现以下错误: “{使用 ==> 符号学时出错 没有足够的输入参数。 错误==>测试6 27 符号学(pe1,'b',pe2,'r');} 我不知道为什么 我希望有人可以看看并帮助我
我的代码是
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;
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 following 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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
导致错误的问题是
semilogy
(如plot
)需要采用semilogy(X1,Y1,'b',X2,Y2,'r ')
如果您想同时绘制多条线。因此,您的semilogy
应该是semilogy(z,pe1,'b',m,pe2,'r')
。您还需要在semilogy
调用中使用z
和m
来确保 x 轴比例正确。您还有其他一些问题。我并没有让它看起来完全像我会做的那样,因为我希望你的代码能够被你识别。但您可能希望将您的代码与以下代码进行逐行比较。我做过的一件事可能是错误的,即将
r
更改为其负数,否则y
太大(因此pe1
和>pe2
为零,通过erfc
)。你的代码已经矢量化,所以我摆脱了 for 循环。请注意,
for n=
循环中不会有n=n+1
;它会自动增加。The problem causing your error is that
semilogy
(likeplot
) expects inputs in the formsemilogy(X1,Y1,'b',X2,Y2,'r')
if you want to plot more than one line at the same time. So, yoursemilogy
should besemilogy(z,pe1,'b',m,pe2,'r')
. You also need thez
andm
in thesemilogy
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 otherwisey
is far to large (sope1
andpe2
were zero, viaerfc
).Your code was already vectorized, so I got rid of the for loops. Note that you wouldn't have
n=n+1
in afor n=
loop; it's incremented automatically.