Are there any element function in MATLAB?

for example I cannot run this: sort(x)(1) nor (sort(x))(1), but I want to do this somehow in one line, for example with a built in function element():
element(sort(x),1);

 Accepted Answer

Yes, you can do it by using subsref(), but it is not at all pretty to do. So it is much easier to write a small extra function:
element = @(X, varargin) X(varargin{:});
This code is not restricted to one subscript and is not restricted to scalar indices. Note though that if you want to use : by itself then you will need to quote it, like
element(sortrows(x), 1, ':')

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!