如何用matlab生成不重複的隨機整數矩陣
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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
反模式 DI anti-patterns
君莫笑-93
2024-05-26 14:24:02
Win10 LTSC 2019 安裝後的一些步驟
SpringCore
2024-05-26 14:20:52
Python 潮流週刊#52:Python 處理 Excel 的資源
豌豆花下貓
2024-05-26 14:19:11
我對微服務架構的簡單理解
HelloLLLLL
2024-05-26 14:17:01
賽克oj The diameter of a rectangle(笛卡爾樹)
SnowLove
2024-05-26 14:10:21
hduoj 1506(笛卡爾樹)
SnowLove
2024-05-26 14:10:21
Qt支持heic圖片顯示
朝十晚八
2024-05-26 14:08:50
Spring的BeanFactoryPostProcessor和BeanPostProcessor區別?
孫小龍
2024-05-26 14:02:20
WPF一個簡單的屬性編輯控件
代碼: public class PropertiesControl : Grid { [TypeConverter(typeof(LengthConverter))] public d
HotSky
2024-05-26 14:02:00
外企也半夜發佈上線嗎?
路人111122233
2024-05-26 14:00:39
從零手寫實現 nginx-01-爲什麼不能有 java 版本的 nginx?
葉止水
2024-05-26 13:59:39
Nginx R31 doc-11-Compression and Decompression 壓縮與解壓縮
葉止水
2024-05-26 13:59:39
【轉】centos7.9源碼安裝mysql5.7.44
tc310
2024-05-26 13:58:49