How do I create a function without getting this Error: Function definitions are not permitted in this context?

I'm trying to create this function, and I am getting an error. I don't know what I am doing wrong...
>> function [y] = myfunc( x, y, z )
y = -9*x - 10*y+ z*(-log(100-x-y)-log(x)-log(y)-log(50-x+y));
end
function [y] = myfunc( x, y, z )
Error: Function definitions are not permitted in this context.

 採用された回答

Stephen23
Stephen23 2017 年 3 月 22 日
編集済み: Stephen23 2017 年 3 月 22 日
Only anonymous functions may be defined in the command window:
>> fun = @(x,y,z)-9*x - 10*y+ z*(-log(100-x-y)-log(x)-log(y)-log(50-x+y));
>> fun(1,2,3)
ans =
-56.599051375363
Other function types (those defined using the keyword function) must be defined in an Mfile.

その他の回答 (1 件)

KSSV
KSSV 2017 年 3 月 22 日
I guess you have copied this under some already existing code. Copy this in fresh m file and save.

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

質問済み:

2017 年 3 月 22 日

編集済み:

2017 年 3 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by