How can I solve this error?

15 views (last 30 days)
Soobin Choi
Soobin Choi on 27 May 2017
Edited: Stephen23 on 28 May 2017
  • 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

Answers (1)

Walter Roberson
Walter Roberson on 28 May 2017
You have
axis([-0.5 0.5-1 1])
and you probably intended
axis([-0.5 0.5 -1 1])
  1 Comment
Stephen23
Stephen23 on 28 May 2017
Edited: Stephen23 on 28 May 2017
... 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])

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!