sorted.m

来自「演示matlab曲线拟和与插直的基本方法」· M 代码 · 共 31 行

M
31
字号
function pointer = sorted(meshsites, sites)
%SORTED Locate sites with respect to meshsites.
%
%   POINTER = SORTED(MESHSITES, SITES) is the  r o w  vector for which
%
%      POINTER(j) = #{ i : MESHSITES(i)  <=  sort(SITES)(j) },  all  j .
%
%   Thus, if both MESHSITES and SITES are nondecreasing, then
%
%      MESHSITES(POINTER(j))  <=  SITES(j)  <  MESHSITES(POINTER(j)+1), all j,
%
%   with POINTER(j) equal to 0 meaning that SITES(j) < MESHSITES(1), and
%   equal to length(MESHSITES) meaning that MESHSITES(end) <= SITES(j).
%
%   Example:
%
%      sorted( 1:4 , [0 1 2.1 2.99 3.5 4 5])
%
%   specifies 1:4 as MESHSITES and [0 1 2.1 2.99 3.5 4 5] as SITES and
%   gives the output  [0 1 2 2 3 4 4], as does
%
%      sorted( 1:4 , [2.99 5 4 0 2.1 1 3.5])
%
%   See also PPUAL, SPVAL.

%   Copyright 1987-2003 C. de Boor and The MathWorks, Inc.
%   $Revision: 1.16 $

[ignored,index] = sort([meshsites(:).' sites(:).']);
pointer = find(index>length(meshsites))-(1:length(sites));

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?