If statement gives wrong result

3 visualizaciones (últimos 30 días)
Xinjie Qian
Xinjie Qian el 17 de Sept. de 2021
Respondida: Shanmukha Voggu el 29 de Sept. de 2021
So I have the follwing Matlab code:
if isKey(containers.Map(str2, str),hasher("YR_.1EC9", 'Algorithm', 'SHA256'))
fprintf('no')
else
fprintf('You can use this name')
end
if I run it, it tells me
You can use this name>>
. But if I seperately excute :
isKey(containers.Map(str2, str),hasher("YR_.1EC9", 'Algorithm', 'SHA256'))
It tells me
ans =
logical
1
I'm so confused as if the logical statement is 1, shouldn't the if statement gives me 'no'?
  1 comentario
KSSV
KSSV el 17 de Sept. de 2021
If it is logical 1 then it should say No. But check while you run the code did you overwrite any variable such that answer is 1. You better run in debug mode and check,

Iniciar sesión para comentar.

Respuestas (1)

Shanmukha Voggu
Shanmukha Voggu el 29 de Sept. de 2021
Hi Xinjie,
There may be several reasons for this issue
1)For example if you wrote the code that is going to make changes to str2 variable after the if-else-end, this might change the output of the isKey function when you run it
2)if the hasher function output is not same when executing it multiple times with the same input
if above statements cannot resolve the issue, then try debugging using the breakpoints. We need some more information about the code in order to reproduce and further investigate the issue
Refer to this for more information.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by