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 ?
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
David Fletcher
on 3 Apr 2018
Edited: David Fletcher
on 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 Comments
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!