how to define functions with variable values

55 ビュー (過去 30 日間)
John
John 2014 年 8 月 21 日
編集済み: Star Strider 2014 年 8 月 23 日
Hello,
I'm trying to define a function x1=-c1/b1*x2+d1/b1, where b1,c1,d1 are defined, but x2 should be kept as a variable. Here's how it all looks at the end

採用された回答

Star Strider
Star Strider 2014 年 8 月 21 日
編集済み: Star Strider 2014 年 8 月 21 日
You can do that with Anonymous Functions:
x1 = @(x2,b1,c1,d1) -c1./b1.*x2+d1./b1;
if you want to include all the constants as arguments,
or:
x1 = @(x2) -c1./b1.*x2+d1./b1;
if you want to pick the constants up automatically from the workspace.
  2 件のコメント
John
John 2014 年 8 月 23 日
Wow! That was quick. It only took you 7 minutes to answer, this other program that I've been using has a way slower community. The anonymous function works great. Though before posting, I tried searching for a similar post and in my findings encountered the anonymous function, without your help I couldn't properly understand how to apply it to my code. Thanks a million!
Star Strider
Star Strider 2014 年 8 月 23 日
編集済み: Star Strider 2014 年 8 月 23 日
My pleasure!
There are some truly brilliant people here. (I have my areas of expertise, but nothing to match others like Roger Stafford, Azzi Abdelmalek, Andrei Bobrov, Cedric Wannaz, and others. MATLAB staffers also appear here from time to time to provide detailed Answers the rest of us cannot.) Stay here if you need help. If you ask your Questions clearly, you will get clear Answers.
Also, contribute your own Answers as you gain expertise.
Apologise for the delay this time — GMT-6 here.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by