comparing between two identical variables returns logic 0?
조회 수: 6 (최근 30일)
이전 댓글 표시
clc
clear
n=0:63;
x1=0:7;
x=[x1 x1 x1 x1 x1 x1 x1 x1];
y=((-1).^n).*x;
[msg,N1]=find_period(x);
disp(msg);
[msg,N2]=find_period(y);
disp(msg);
%Taking 1 period of Y
y1=zeros(1,N2);
for i = 1:N2
y1(i)=y(i);
end
if N1==N2
fprintf('N1=N2=%d \n', N1);
end
ak=our_fourier_series(x1);
bk=our_fourier_series(y1);
for i =1:4
if (bk(i)==ak(4+i))
disp('bk=ak-N/2')
end
end
bk(6)==ak(2)
bk(6)
ak(2)
as you can see in the command window bk(6) equals ak(2)
but comparing between them returns logic 0
how is that even possible?
댓글 수: 0
채택된 답변
Stephen23
2020년 5월 5일
편집: Stephen23
2020년 5월 5일
"as you can see in the command window bk(6) equals ak(2)"
Nope. Just looking at some floating point values displayed in the command window (or variable viewer, etc.) is not a valid way to determine their exact values (and hence is not valid to decide if they are equal). Those values are certainly not equal, which you will see when you view them at a higher precision, e.g. dowload this:
"but comparing between them returns logic 0 how is that even possible?"
Simply because the values are not equal. Read these to know why they are not equal:
This is worth reading as well:
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!