Error (The value assigned to variable <variable_name> might be unused)

조회 수: 2 (최근 30일)
Ahmad Nabil Hilman Ahmad Jaafar
Ahmad Nabil Hilman Ahmad Jaafar 2014년 12월 9일
편집: Sean de Wolski 2014년 12월 9일
Hello, the code that I have below keep showing error that I can't identify myself(line 13,14,20.26,28,30). Anyone can help resolve it? For my assignment. Thank you in advance
function bpskd(g,f) %Define variables g and f in the command window %Input carrier frequency as a multiple of if nargin>2 error('Too many input arguments'); elseif nargin==1 f=1; end if f<1; error('Frequency must be greater than 1'); end t=0:2*pi/99:2*pi; cp=[];sp=[]; mod=[];mod=[];bit=[]; for n=1:length(g); if g(n)==0; die=-ones(1,100); se=zeros(1,100); %Signal else g(n)==1; die=ones(1,100); se=ones(1,100); %Signal end c=sin(f*t); cp=[cp die]; %Amplitude mod=[mod c]; %Carrier bit=[bit se]; %Binary signal end bpsk=cp.*mod; %BPSK Signal subplot(2,1,1); plot(bit,'LineWidth',1.5); grid on; xlabel('time');ylabel('Amplitude'); title('binary signal'); axis([0 100*length(g) -2.5 2.5]); subplot(2,1,2); plot(bpsk,'LineWidth',1.5); grid on; xlabel('time');ylabel('Amplitude'); title('BPSK signal'); axis([0 100*length(g) -2.5 2.5]);

답변 (2개)

David Young
David Young 2014년 12월 9일
Your code is almost impossible to read - you need to format it using the "{} Code" button.
The message is a warning rather than an error. It means that you have assigned a value to a variable and then you don't appear to use that value.
For example, I think your code has a line starting
t =
which assigns a value to the variable t. Where is the value of t used later in the function? If it is not used, you can omit the line starting "t =" and that will remove the warning.

Sean de Wolski
Sean de Wolski 2014년 12월 9일
편집: Sean de Wolski 2014년 12월 9일
Usually for me, these warnings mean I have a typo.
xxxxxx = 1:10
plot(xxxxx)
You can click on the variable to highlight everywhere it is used to see if something is missing it.

카테고리

Help CenterFile Exchange에서 Test and Measurement에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by