那我这个呢?
function [G_matrix coded_msg] =en(msg)
K = 10; % 信息分组长度
N = 20; % 预期生成的编码符号的个数,N要大于K*Z
c = 0.03; % 此参数影响较大
delta = 0.2; % c和delta为鲁棒孤子分布中的两个参数
% ---------------- ideal solition ---------------------
rho(1) = 1/K; %
d = (2:K); % 理想孤子分布
rho(2:K) = 1./(d.*(d-1)); %
% -----------------------------------------------------
S = c*log(K/delta)*sqrt(K); % 鲁棒孤子分布,译码过程中预期的度为1的校验节点的数目
KS = round(K/S);
% ------------------- tau函数 ---------------------------
tau = zeros(1,K); %
for d = 1:K %
if d<=(round(K/S)-1) %
tau(d) = S/(K*d); %
elseif d == round(K/S) %
tau(d) = S/K*log(S/delta); %
end %
end %
% ----------------- robust solition ---------------------
Z = 0; %
for d = 1:K %
Z = Z+tau(d)+rho(d); % 鲁棒孤子分布函数
end %
mu =(rho+tau)/Z;
KZ = round(K*Z);
disp('为了保证译码成功的概率至少为1-δ,接收端需要的编码数据包的数量为:');
disp('K*Z = ');
disp(KZ); % N要大于K*Z
G_matrix = []; % 生成矩阵 %
coded_msg = []; % 编码符号序列 % 变量定义
index = 0; % 在后续程序中用来统计度为1的编码符号的个数 %
for i = 1:N % 对每个编码符号
d = randsrc(1,1,[1:K;mu]); % 在1~K内,随机选择一个服从鲁棒孤子分布的数,作为该编码符号的度
% ----------------------------------------------------------------
rand_num = []; % 用于存放产生的d个不同的数(表示d个不同的信源符号)
s = randsrc(1,1,[1:K]); % 产生第一个随机数
if d == 1
rand_num = [rand_num s];
else
rand_num = [rand_num s];
for p = 2:d
nu = randsrc(1,1,[1:K]);
% ------------------------------------
ii = 1; %
while ii <=(p-1) %
if find(nu == rand_num(ii)) %
nu = randsrc(1,1,[1:K]); %
ii = 1; % 确保每次生成的随机数与前面的数不同
else %
ii = ii+1; %
end %
end %
% ------------------------------------
rand_num = [rand_num nu];
end
end
% ----------------------------------------------------------------
% ------------------------------
G_column = zeros(K,1); %
for j = 1:d % 生成与每个编码符号相对应的生成矩阵的列向量
G_column(rand_num(j)) = 1; %
end %
% ------------------------------
% ------------------------------
G_matrix = [G_matrix G_column]; % 将生成的列向量G_column存放到生成矩阵G_matrix中
% ------------------------------
% ------------------------------------------------------
encode_s = msg(rand_num(1)); %
if d == 1 %
encode_s = msg(rand_num(1)); %
index = index+1; % 统计度为1的编码符号的个数 %
else % 生成每个编码符号
for k = 2:d %
encode_s = xor(encode_s,msg(rand_num(k))); %
end %
end %
% ------------------------------------------------------
coded_msg = [coded_msg encode_s]; % coded_msg存储编码符号
% ------------------------------------------------------
end
为何每次只输出一个,而且是后面的,把那个放后面就输出那个