create a function handle extracting pieces from a matrix function handle
Show older comments
I created a Matrix function using function handle @ like
A=@(x) [1 2 x; 2*x x.^2 3]; %it's an example
i need to create another function extracted from the previous one
B=@(x) A(x) without the second column
therefore size(A)=2x3 and size(B)= 2x2;
if it wasn't for the handle: B=A(:,[1 3])
ty for your help
Accepted Answer
More Answers (1)
Walter Roberson
on 4 Jun 2013
B=@(x) subsref(A(x), struct('type', '()', 'subs', {':', [1 3]}));
Note: if the requirement is "all of whatever is there, except column 2", rather than "select only column 1 and column 3", then in order to avoid evaluating A(x) twice, one would have to add a helper anonymous function (because a subscript of 'end' is not allowed at the subsref level and must be converted to numeric form.)
1 Comment
Sergio Codeluppi
on 4 Jun 2013
Categories
Find more on Customize Object Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!