How to extract one component in a vector function
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Guillaume
le 4 Nov 2015
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!