Matlab executable doing incorrect multiplication

Any help on this matter would be greatly appreciated, I cannot figure out what's wrong.
I've used an old version of Matlab (2010a) to compile various functions into an executable. The command I use to build the executable is "mcc -v -m..." so that I get a stand-alone C application.
When I run my scripts within Matlab, I receive all the correct answers. However, when I run the scripts using the executable there is a calculation error. It's simple multiplication, I'm actually converting minutes to nanoseconds, minutes * 6e10. For instance, if I use 5 minutes I should receive back 3e11. That is the answer I get when I run the script containing the calculation in the Matlab environment. When I run the executable, the answer I get is 3.18e12.
I've tried moving that specific line into a different script, making it a separate function, renamed the variables, among other trouble shooting tactics. No luck still. When I enter in 1 minute, I receive back 2.96e12. Eventually I took this line out and input nanoseconds directly instead of minutes. This remedied the issue, but now it's a different line that is being calculated incorrectly. It uses the same basic multiplication. What's frustrating is that I have almost identical lines of code within the scripts that are included in the executable and they work fine.
I've compared all of the other calculations from the executable vs in my Matlab environment (I've been displaying the calculations on the command prompt for the executable). All other calculations are being done correctly and the correct values are being used for the multiplication.
A friend suggested that it might be because of the variable size in C, but we ran the same line for a smaller number (ie, milliseconds instead of nanoseconds) and it still produces the wrong answer. I'm ripping out my hair with this one, I can't find any other forums discussing a similar issue. ANY help would be great! Thanks!

回答 (1 件)

Steven Lord
Steven Lord 2015 年 7 月 2 日

2 投票

You're calling your executable as "executableName 5", right? That passes the STRING '5' into your executable not the NUMBER 5. The ASCII value of '5' is 53, and 53*6e10 is 3.18e12. This is documented (even though that's the most recent documentation, I believe what it describes is applicable to release R2010a as well) and the last section of that documentation page includes a description of a suggested solution.

カテゴリ

ヘルプ センター および File ExchangeMATLAB Compiler についてさらに検索

質問済み:

2015 年 7 月 2 日

回答済み:

2015 年 7 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by