組み込み関数の中身が知りたい

조회 수: 24 (최근 30일)
hirokazu machida
hirokazu machida 2021년 9월 7일
댓글: hirokazu machida 2021년 9월 8일
MATLAB内で使用​されている組み込み関​数(私自身知りたいの​は"sort"です)​の中身のコードがどの​ようになっているかを​見るためにはどのよう​にすればよいでしょう​か.ちなみに現在so​rt関数を開くとすべ​て説明文(コメントア​ウト)で,どのように​構築されているかは記​載されておりません.​下記に示しておきます​.
%SORT Sort in ascending or descending order.
% B = SORT(A) sorts in ascending order.
% The sorted output B has the same type and size as A:
% - For vectors, SORT(A) sorts the elements of A in ascending order.
% - For matrices, SORT(A) sorts each column of A in ascending order.
% - For N-D arrays, SORT(A) sorts along the first non-singleton dimension.
%
% B = SORT(A,DIM) also specifies a dimension DIM to sort along.
%
% B = SORT(A,DIRECTION) and B = SORT(A,DIM,DIRECTION) also specify the
% sort direction. DIRECTION must be:
% 'ascend' - (default) Sorts in ascending order.
% 'descend' - Sorts in descending order.
%
% B = SORT(A,...,'MissingPlacement',M) also specifies where to place the
% missing elements (NaN/NaT/<undefined>/<missing>) of A. M must be:
% 'auto' - (default) Places missing elements last for ascending sort
% and first for descending sort.
% 'first' - Places missing elements first.
% 'last' - Places missing elements last.
%
% B = SORT(A,...,'ComparisonMethod',C) specifies how to sort complex
% numbers. The comparison method C must be:
% 'auto' - (default) Sorts real numbers according to 'real', and
% complex numbers according to 'abs'.
% 'real' - Sorts according to REAL(A). Elements with equal real parts
% are then sorted by IMAG(A).
% 'abs' - Sorts according to ABS(A). Elements with equal magnitudes
% are then sorted by ANGLE(A).
%
% [B,I] = SORT(A,...) also returns a sort index I which specifies how the
% elements of A were rearranged to obtain the sorted output B:
% - If A is a vector, then B = A(I).
% - If A is an m-by-n matrix and DIM = 1, then
% for j = 1:n, B(:,j) = A(I(:,j),j); end
%
% The sort ordering is stable. Namely, when more than one element has the
% same value, the order of the equal elements is preserved in the sorted
% output B and the indices I relating to equal elements are ascending.
%
% Examples:
% % Sort a vector in ascending order
% sort([0 3 1 0 2 0 1 6])
% % Sort each column or row of a matrix
% A = [3 7 5; 0 4 2]
% B1 = sort(A,1) % sort each column
% B2 = sort(A,2) % sort each row
% % Sort complex numbers according to their real part
% A = [1+1j ; 1-1j ; -2-2j ; 0 ; -2+2j]
% B = sort(A,'ComparisonMethod','real')
%
% See also ISSORTED, SORTROWS, MIN, MAX, MINK, MAXK.
% Copyright 1984-2017 The MathWorks, Inc.
% Built-in function.

채택된 답변

Hernia Baby
Hernia Baby 2021년 9월 7일
似たような質問 でもあるのですが、
既にビルトされたものなので、おそらく中身を見ることはできません…
Mathwarks社員になるか 交渉 …になるみたいです
ソートというアルゴリズム自体に興味ある場合は
図で分かりやすく紹介されていますので、ご参照ください
  댓글 수: 2
Hernia Baby
Hernia Baby 2021년 9월 7일
公式ではないですが… File Exchange にもあるにはあったりするので、興味あれば探してみてください
hirokazu machida
hirokazu machida 2021년 9월 8일
回答ありがとうございます.
やはり見る方法はありませんよね..
File Exchangeも見させていただきました.対象がcellstrなのでdoubleに変更しながら解読していきたいと思います.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Masahiro Horie
Masahiro Horie 2021년 9월 7일
Octaveのsort関数を調べると参考になるかもしれません。
  댓글 수: 1
hirokazu machida
hirokazu machida 2021년 9월 8일
回答ありがとうございます.
早速Octaveをダウンロードし,sort関数を調べてみたのですが,やはり組み込み関数となっているため,確認することができませんでした.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!