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

16 visualizaciones (últimos 30 días)
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]);

Respuestas (2)

David Young
David Young el 9 de Dic. de 2014
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 el 9 de Dic. de 2014
Editada: Sean de Wolski el 9 de Dic. de 2014
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.

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by