ssort.m
来自「matlab宝典,电子工业出版社,包含该书的源码4-6章」· M 代码 · 共 28 行
M
28 行
function out=ssort(a)
% SSORT程序代码按照升序来排列数据
% 需要提醒用户的是,该程序代码在排序
%方面没有太大效率. 如果需要对大型数据
% 进行排序,请使用MATLAB的内置函数
% Define variables:
% a Input array to sort
% ii Index variable
% iptr Pointer to min value
% nvals Number of values in "a"
% out Sorted output array
% temp Temp varible for swaping
nvals=size(a,2);
for ii=1:nvals-1
iptr=ii;
for jj=ii+1:nvals
if a(jj)<a(iptr)
iptr=jj;
end
end
if ii~=iptr
temp=a(ii);
a(ii)=a(iptr);
a(iptr)=temp;
end
end
out=a;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?