comparing between two identical variables returns logic 0?
5 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/290385/image.png)
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!