Cannot use equal operator to test function argumants

1 visualización (últimos 30 días)
Barak
Barak el 15 de Nov. de 2022
Respondida: Fangjun Jiang el 15 de Nov. de 2022
I have the following code and I am trying to test if either one of user inputs (out of 3) equals the sum of the other 2 user inputs.
Althought I enter 3 values thatc should return true and therfore the if should happen, it does not.
When I try to write the if condition with a single '=' it des not even let me excute the code.
So any assistance is much appriciated.
function testArgs()
a = input('Enter first value: ');
b = input('Enter first value: ');
c = input('Enter first value: ');
anum = str2double(a);
bnum = str2double(b);
cnum = str2double(c);
if anum==bnum+cnum || bnum==anum+cnum || cnum==anum+bnum
fprintf('some msg');
end

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 15 de Nov. de 2022
a = input('Enter first value: ')
"a" is already a numerical value.
You don't need all the str2double() calls.
when you call str2double(), it creates a NaN (Not a Number)
a=1
a = 1
str2double(a)
ans = NaN

Más respuestas (0)

Categorías

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

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by