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);

 Respuesta aceptada

Walter Roberson
Walter Roberson el 14 de Jun. de 2016
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, ':')

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 14 de Jun. de 2016

Respondida:

el 14 de Jun. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by