Can Anonymous functions contain unknown variables?
显示 更早的评论
I'm looking at an Anonymous function structured like this:
g = @(x,theta,u,dt)([1,0;0 exp(-dt/theta(5))]*x + [1;theta(3)]*u);
where u and dt are known, but x and theta are not. When I put a break-point before and after this function and check the values of x and theta, they are still undefined, but the code runs. What's going on here?
采纳的回答
更多回答(1 个)
Star Strider
2016-8-16
2 个投票
The function itself will not throw an error simply because it exists. Like any other function, you have to call it. That function call could throw an error if all the variables are not defined (whether they’re inherited from your workspace or passed as arguments) and the function is otherwise correctly-written, but the function itself will not.
类别
在 帮助中心 和 File Exchange 中查找有关 Variables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!