资源简介
使用matlab编程排序,有输入功能,调用函数等
在同时携带第二个数组arr 2的同时,按升序对数组arr 1进行排序通常是有用的。在这样的排序中,每次数组arr 1的元素与arr 1的另一个元素交换时,数组arr 2的对应元素也被交换。当排序结束时,数组arr 1的元素按升序排列,而与数组arr 1的特定元素相关联的数组arr 2元素仍然与它们关联。例如,假设我们有以下两个数组:

代码片段和文件信息
% script file: paixu.m
%
% Purpose:
% To read in the input data set sort array1 into ascending
% order suing the selection sort algorithmarray2 carry with
% the array1and to write the sorted data to the Command Window.
% This program calls function “ssort“ to do the actual sorting.
%
% Record of revisions:
% Data Programmer Description of change
% ======== ============ ========================
% 18/07/04 苗锦宝 Original code
%
% Define variables:
% array1 --Input data array1
% array2 --Input data array2
% ii --Index variable
% nvals --Number of the array
% sorted --Sorted data array
% Prompt for the number of the array in the data set
nvals=input(‘Enter the number of values to sort:‘);
% Preallocate array1
array1=zeros(1nvals);
% Get input numbers
for ii=1:nvals
string=[‘Enter the array1 ‘ int2str(ii) ‘ : ‘];
array1(ii)=input(string);
end
% Preallocate array2
array2=zeros(1nvals);
% Get input numbers
for ii=1:nvals
string=[‘Enter the array2 ‘ int2str(ii) ‘ : ‘];
array2(ii)=input(string);
end
% Now sort the data
sorted=ssort(array1array2);
% Display the sorted result
fprintf(‘\nSorted data:\n‘);
fprintf(‘\n a=‘);
fprintf(‘%8.1f‘sorted(1:));
fprintf(‘\n b=‘);
fprintf(‘%8.1f‘sorted(2:));
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-01-01 21:43 排序\
文件 22062 2018-07-03 21:12 排序\Final Test.docx
文件 1395 2018-07-03 20:22 排序\paixu.m
文件 1464 2018-07-03 19:51 排序\ssort.m
- 上一篇:Lorenz系统和Chua系统MATLAB仿真
- 下一篇:最小二乘法系统辨识
相关资源
- matlab_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
评论
共有 条评论