Why do my functions suddenly return values in ASCII code?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Winter Vee
am 21 Jun. 2022
Kommentiert: Steven Lord
am 21 Jun. 2022
I have made simple functions in MatLab. For example:
function add(a,b)
fprintf('%d + %d = %d\n',a,b,a+b);
end
This used to work. However, using MatLab again after a while, this same function now returns values in ASCII code. Basically, given the inputs "4" and "5",
Before:
4 + 5 = 9
Now:
52 + 53 = 105
I don't remember doing anything that would cause this change. Simply typing "4 + 5" in the command window returns 9, but the problem arises when I make functions. Advice would be appreciated. (Version: R2022a)
4 Kommentare
Stephen23
am 21 Jun. 2022
"but I just want to fix the formatting if that makes sense."
Changing the formatting cannot "fix" the fact that you call the function with incorrect inputs.
Akzeptierte Antwort
Walter Roberson
am 21 Jun. 2022
You accidentally used "command function equivalence". When you name a function without using () then the arguments you input are passed to the function as character vectors.
add 4 5
add(4, 5)
function add(a,b)
fprintf('%d + %d = %d\n',a,b,a+b);
end
2 Kommentare
Steven Lord
am 21 Jun. 2022
This also commonly happens in a standalone application. See the "Using a MATLAB File You Plan to Deploy" section on this documentation page.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!