How can I solve this error?

15 Ansichten (letzte 30 Tage)
Soobin Choi
Soobin Choi am 27 Mai 2017
Bearbeitet: Stephen23 am 28 Mai 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

Antworten (1)

Walter Roberson
Walter Roberson am 28 Mai 2017
You have
axis([-0.5 0.5-1 1])
and you probably intended
axis([-0.5 0.5 -1 1])
  1 Kommentar
Stephen23
Stephen23 am 28 Mai 2017
Bearbeitet: Stephen23 am 28 Mai 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])

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by