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 ExchangeShifting 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