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
在这个例子中,我有四种不同类型的“fixed_part”。
答案 0 :(得分:0)
用你想要的完整矩阵回答:
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 =
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
“更多修复部分”已经增加了吗?