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