Calling function from within embedded matlab function

I was wondering if someone could help me with a very basic question about matlab programming (I have spent too much time trying to find the answer online with no luck). I have an embedded matlab function I am calling from simulink. Within that function I want to call another function (just trying to modularize the code a little). I can't nest the function within a function as I get an error so I tried to put the function definition after my "end" to the original function (i.e. in the same file), but I get function undefined. Does matlab not allow calling a function from within an embedded matlab function or am I just doing something wrong? Below is what I am trying to do:
function f1 = fcn(x)
%some code here
y = f2(z);
end
function f2 = fcn (xval)
%code
end

1 件のコメント

amin nzh
amin nzh 2019 年 6 月 18 日
Hello. Did you find the answer? I have a same problem. Could you please explain the answer if you have solved it?

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2011 年 9 月 7 日

0 投票

The name of a function is the first name to the right of the '=', not the name to the left of the '='. You have named both of your functions as "fcn". You probably want something like
function y = f1(x)
%some code here
y = f2(z);
end
function result = f2(xval)
%code
result = ... %something
end

その他の回答 (0 件)

カテゴリ

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

質問済み:

2011 年 9 月 7 日

コメント済み:

2019 年 6 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by