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 visualización (últimos 30 días)
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

Respuestas (1)

David Fletcher
David Fletcher el 3 de Abr. de 2018
Editada: David Fletcher el 3 de Abr. de 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

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by