Error (The value assigned to variable <variable_name> might be unused)
2 次查看(过去 30 天)
显示 更早的评论
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]);
0 个评论
回答(2 个)
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.
0 个评论
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Test and Measurement 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!