필터 지우기
필터 지우기

why i get the undefined variable message?

조회 수: 2 (최근 30일)
Gn Gnk
Gn Gnk 2019년 10월 15일
편집: KALYAN ACHARJYA 2019년 10월 15일
I have this code for QAM:
p=(sign(randn(N,1))+2)/2;
for i=1:length(p/2)-1
if p(i)==0 && p(i+1)==0
s(i)=1+1i;
elseif p(i)==0 && p(i+1)==1
s(i)=1-1i;
elseif p(i)==1 && p(i+1)==1
s(i)=-1-1i;
elseif p(i)==1 && p(i+1)==0
s(i)=-1+1i;
end
end
scatterplot(s);
and when i try to run this thing i get the message :undefined variable 's'.
Do you know what should i do to fix this.I dont think its a code fault but its a matlab problem .
Thank you.
  댓글 수: 1
Adam Danz
Adam Danz 2019년 10월 15일
편집: Adam Danz 2019년 10월 15일
If none of your conditions are met, s will never be defined. So when you get to the last line of your code, s is undefined.
The problem is that none of your conditions are being met and 's' has no default value for when that happens.

댓글을 달려면 로그인하십시오.

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 10월 15일
편집: KALYAN ACHARJYA 2019년 10월 15일
and when i try to run this thing i get the message :undefined variable 's'.
First:
Because you did not defined N
Second for S, considering N=10 here, whatever you choose the value of N, p reflects numbers of 0.5 and 1.5
Also
p =
0.5000
1.5000
1.5000
0.5000
1.5000
0.5000
0.5000
1.5000
1.5000
1.5000
Neither the any if condition is true for p value, so "s" value didnot get assign. Beacuse p(i) and p(i+1) ==0 or 1 is not true for any case

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Pole and Zero Locations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by