How can I solve this error?

15 次查看(过去 30 天)
Soobin Choi
Soobin Choi 2017-5-27
编辑: Stephen23 2017-5-28
  • I was designing a C program that calculates FS partial-sum approximation but getting this error. How can i solve this?*
Warning: Imaginary parts of complex X and/or Y arguments ignored
Error using axis>LocSetLimits (line 308)
Vector must have 4, 6, or 8 elements.
Error in axis (line 101)
LocSetLimits(ax(j),cur_arg,names);
Code that I used is looks like below:
>>k = 1:1:99;
>>t = linspace(-0.5,0.5,400);
>>B = zeros(1,100);
>>B(1) = 0; % for k=0
>>B(2:1:100) = 8*sin(k*pi/2).*exp(1i*pi*k/2)./(1i*(pi*k).^2);
>>xJhat(1,:) = B(1)*cos(0*2*pi*t);
>>for k = 2:1:100
Bcos(k,:) = B(k)*cos((k-1)*2*pi*t);
xJhat(k,:) = xJhat(k-1,:)+B(k)*cos((k-1)*2*pi*t);
end
>>j = [1 3 7 29 99]+1;
>>for i = 1:1:5
subplot(5,2,2*i-1);plot(t,Bcos(j(i),:));
ylabel(['B[' num2str(j(i)-1) ']cos(' num2str(j(i)-1) '\omega_0n)']);
xlabel('n');axis([-0.5 0.5-1 1]);
subplot(5,2,2*i);plot(t,xJhat(j(i),:));
ylabel(['x' num2str(j(i)-1) '(t)']);
xlabel('n');
end

回答(1 个)

Walter Roberson
Walter Roberson 2017-5-28
You have
axis([-0.5 0.5-1 1])
and you probably intended
axis([-0.5 0.5 -1 1])
  1 个评论
Stephen23
Stephen23 2017-5-28
编辑:Stephen23 2017-5-28
... which is a good example of why it is better to explicitly separate array elements using commas, rather than relying on implicit separation using spaces:
axis([-0.5,0.5,-1,1])

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by