comparing between two identical variables returns logic 0?

9 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Stephen23
Stephen23 el 5 de Mayo de 2020
Editada: Stephen23 el 5 de Mayo de 2020
"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:

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by