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

 채택된 답변

Walter Roberson
Walter Roberson 2016년 6월 14일

0 개 추천

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, ':')

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2016년 6월 14일

답변:

2016년 6월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by