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 回表示 (過去 30 日間)
Muhammet Bilgiç
Muhammet Bilgiç 2018 年 4 月 3 日
編集済み: David Fletcher 2018 年 4 月 3 日
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

回答 (1 件)

David Fletcher
David Fletcher 2018 年 4 月 3 日
編集済み: David Fletcher 2018 年 4 月 3 日
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

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by