How to extract one component in a vector function
3 次查看(过去 30 天)
显示 更早的评论
I have a vector whose 2 components are functions of x as follows
v = @(x) [x^2 ; x^2]
and I want now to introduce the new function h(x) which is defined as the first component of the vector v.
My question is how to define the function h(x). Thank you in advance.
0 个评论
采纳的回答
Guillaume
2015-11-4
If you want to use an anonymous function as you've done for v, you run into the limit of matlab languages, you cannot indeed do:
h = @(x) v(x)(1)
as matlab won't let you chain () expressions.
However, indexing is implemented by subsref, so you can call subsref directly. It makes for one ugly syntax though:
h = @(x) subsref(v(x), struct('type', '()', 'subs', {{1}})); %will return 1st element of v(x)
Note the double wrapping of the index {{1}} into a cell array required by struct.
更多回答(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!