MATLAB: MATLAB miscalculates simple multiplication

miscalculation

Hello, excuse me for this question, I hope that I am not overloocking something really simple. My code is the following:
for a = 1:len
houses{a} = data{a*3-2};
try
timet{a} = datetime(data{a*3-1})-startTime;
catch error
disp(data{a*3-1})
disp(a*3-1)
disp(a)
disp(a*3)
break
end
distance{a} = data{a*3};
end
The important part is the part in the catch statement. I inserted it to find the cause of my problem and let maplab display me the value for a and a*3 in the end. Matlab returns:
>> 10923
>> 32767
If I type in 10923*3 manually it returns
>> 32769
(which is the right solution)
Does anyone see where my mistake is? I'm sorry, I just can't figure it out right now. Best, Viviane

Best Answer

Your 'a' values somehow got converted to type int16, which have a maximum value of
>> disp( intmax('int16'))
32767
If you convert the data to double type, the problem should go away
>> disp(double(a)*3)