I am getting that error explanation"function [out] = celsi2farh( x, i ) ↑ Error: Function definition not supported in this context. Create functions in code file." Could you please helpm me to get rid of this error ?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
function [out] = celsi2farh( x, i ) % x: temperature either celsius or fahrenheit % i: flag - 0: F, 1: C, otherwise: error
if i==0 % F -> C out = (5./9.)*(x-32.0) elseif i==1 % C -> F out = (9./5.)*x + 32.0 else error("other value") end
0 Kommentare
Antworten (1)
David Fletcher
am 3 Apr. 2018
Bearbeitet: David Fletcher
am 3 Apr. 2018
I think recent versions of Matlab (I don't know from which version) allow a function to be put on the bottom of a script file, but generally functions need to be saved in their own file on the Matlab search path, and the file name should be the same name as the function name. Functions are then called from the command line (or from a script file) by their name.
celsi2farh(0,1)
out =
32
ans =
32
Seems to work
0 Kommentare
Siehe auch
Kategorien
Mehr zu File Operations 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!