test_ssort.m
来自「图像分割算法的Matlab源程序」· M 代码 · 共 44 行
M
44 行
% Script file: test_ssort.m
%
% Purpose:
% To read in an input data set, sort it into ascending
% order using the selection sort algorithm, and to
% write the sorted data to the Command window. This
% program calls function "ssort" to do the actual
% sorting.
%
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 12/19/98 S. J. Chapman Original code
%
% Define variables:
% array -- Input data array
% ii -- Index variable
% nvals -- Number of input values
% sorted -- Sorted data array
% Prompt for the number of values in the data set
nvals = input('Enter number of values to sort: ');
% Preallocate array
array = zeros(1,nvals);
% Get input values
for ii = 1:nvals
% Prompt for next value
string = ['Enter value ' int2str(ii) ': '];
array(ii) = input(string);
end
% Now sort the data
sorted = ssort(array);
% Display the sorted result.
fprintf('\nSorted data:\n');
for ii = 1:nvals
fprintf(' %8.4f\n',sorted(ii));
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?