error in matlab arithmetic operations ?

3 views (last 30 days)
LO on 7 Jul 2020
Commented: LO on 7 Jul 2020
I am puzzled by the result of this operation in matlab:
I have a var that equals 3
I am trying to calculate (var-1)*60
instead of getting 120 I get 3000, it may have something to do with number formatting ?
LO on 7 Jul 2020
Thanks John
the var is actually not called var (as rightfully StarStrider pointed out, this would be a function). The var is just the value in a text box which equals 2 - I am sure of this: I tried to display separately in a text box (I am using a GUI with app designer) and it is = 2. I have no idea of why

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 7 Jul 2020
Your variable named var (which is a bad idea, because var already has a meaning in MATLAB) is not 3. It is '3'.
xDouble = 3;
xChar = '3';
The ASCII value of '3' is 51. When you subtract 1 from '3' the result is the double value 50 and 50*60 is 3000.
  1 Comment
LO on 7 Jul 2020
that is what I wanted to hear :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!