フィルターのクリア

How to use one function handle to generate function handles returning different values?

2 ビュー (過去 30 日間)
Qun Wu
Qun Wu 2017 年 4 月 8 日
編集済み: Stephen23 2017 年 4 月 9 日
For example, here is my function:
function [ fy, fz ] = funtest( x,a )
fy = x + 1 + a;
fz = x + 1 + a + 2*a;
end
We can see fy and fz are similar, so I do not want to write two functions for each of them respectively. I do not use the function to get function value. I want to get function handles. Such as, in command window, when I type in
a = 3; f1 = @(x)funtest(x,a)
something like this, and I have a function handle for fy. MeanWhile maybe
f2 = @(x)funtest(x,b)...
having a little bit modification for fz.
I tried
f1 = @(x)funtest(x,a)(1)
for fy, and get an error "Error: ()-indexing must appear last in an index expression." And
[f1, f2] = @(x)funtest(x,a)
gets an error "Error: Only functions can return multiple values." .
Any suggestion is appreciate. Have a beautiful day!

回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by