How to use one function handle to generate function handles returning different values?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Calendar에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!