Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 矩阵中的随机排序位_Matlab - Fatal编程技术网

Matlab 矩阵中的随机排序位

Matlab 矩阵中的随机排序位,matlab,Matlab,你能帮我吗。我有矩阵,但我想在矩阵中有更多的“固定部分”,并被随机选择。同样重要的是,每一行都是唯一的。你能帮我吗 clear all clc ntags = 50; fixed_part = 20; IDlength = 64; tag_population = [zeros(ntags, fixed_part), floor(rand(ntags,IDlength-fixed_part)*2)]; tag_population = unique(tag_population,'

你能帮我吗。我有矩阵,但我想在矩阵中有更多的“固定部分”,并被随机选择。同样重要的是,每一行都是唯一的。你能帮我吗

clear all
clc
ntags = 50;
fixed_part = 20;
IDlength = 64;




tag_population = [zeros(ntags, fixed_part), floor(rand(ntags,IDlength-fixed_part)*2)];   
tag_population = unique(tag_population,'rows');
看看这个矩阵:

0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 
0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 0
0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1
0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1

在这个例子中,我有四种不同类型的“固定零件”

要使用您想要的完整矩阵进行回答:

for t =  1:size(A,1)
   Y(t,:) = circshift(A(t,:)',randi([1 size(A,2)],1,1)')

%//EDIT added first 4 digits cannot be 0
   while sum(Y(t,1:4) > 0) 
   Y(t,:) = circshift(A(t,:)',2)
   end

%//Be warned, can run into infinite loop if the first 4 digits must contains at least a 1.

end
其中A是您的输入矩阵

Y=


“更多固定部件”已经增加了,对吗?

对不起,“更多固定部件”是什么意思?更高的值?@hbaders,“fixed_part”表示随机排序的“0”和“1”组之间有多少个“0”。我想要更多的“固定部分”在矩阵中。我可能仍然理解错了(如果是这样的话,很抱歉),但是你不能将
fixed\u part
设置为一个更高的数字,例如30,以获得这个数字吗?@hbaderts,是的,但是我会让矩阵只包含一个“固定部分”。“更多固定部分”听起来非常SNL:-)这很好,但我不应该在前四个位置有1。@NikolaC我编辑了我的答案,以纳入变化。这是一条不断前进的道路。这不是工作
 0     0     0     0     1     1     0     0     0     0     1     0     0     0     0     0
 0     0     0     0     1     0     0     0     0     0     0     0     1     1     1     0
 0     0     0     0     0     1     1     1     0     0     0     0     0     0     0     0
 0     0     0     0     0     0     1     1     0     0     0     0     0     0     0     1
 0     0     0     0     0     0     0     0     0     1     0     1     0     0     0     0
 0     0     0     0     0     0     1     0     0     0     0     0     0     0     0     0
 0     0     0     0     0     0     1     0     0     0     0     1     1     0     0     0
 0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     0
 0     0     0     0     0     1     0     0     0     0     0     0     0     0     0     0
 0     0     0     0     0     1     1     1     0     0     0     0     0     0     0     0