function s= sampling(low,up,m,n)
%该函数用来产生不重复的随机整数矩阵
%low—随机整数下界;up—随机整数上界;m,n—随机矩阵维度
%编写函数时的测试数据
if ~nargin
low=1;
up=100;
m=1;
n=20;
end
s=[];
t=0;
while 1
temp=randi([low,up],1);
if(isempty(find(s==temp)))
s=[s temp];
t=t+1;
end
if(t>=m*n)
break;
end
end
s=reshape(s,m,n);
%该函数用来产生不重复的随机整数矩阵
%low—随机整数下界;up—随机整数上界;m,n—随机矩阵维度
%编写函数时的测试数据
if ~nargin
low=1;
up=100;
m=1;
n=20;
end
s=[];
t=0;
while 1
temp=randi([low,up],1);
if(isempty(find(s==temp)))
s=[s temp];
t=t+1;
end
if(t>=m*n)
break;
end
end
s=reshape(s,m,n);

本文介绍了一个MATLAB函数,用于生成指定范围内不重复的随机整数矩阵。该函数接受四个参数:随机整数的下界、上界及所需矩阵的行数和列数。
5万+

被折叠的 条评论
为什么被折叠?



