function name as a variable
3 次查看(过去 30 天)
显示 更早的评论
Is it possible to do the following?
variablefun.m
function variablefun(fun)
fun
function fun1
end
function fun2
end
end
command window
variablefun(fun1)
variablefun(fun2)
2 个评论
采纳的回答
Walter Roberson
2025-3-31
variablefun('fun2')
function variablefun(fun)
eval(fun)
function fun1
disp('fun1 here')
end
function fun2
disp('fun2 here')
end
end
However, you cannot use
writefun(fun2)
as fun2 will not be defined at that point. MATLAB always works by evaluating parameters first before calling the given function, so in MATLAB it is not possible at all to define special "unevaluated parameter" behaviour (such as Maple is able to do.)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!