我无法修复此程序中的错误。该程序中的错误在以下行中:
mx(mslen+1:length(mx))=r;
???在赋值 A(I) = B 中,B 和 I 中的元素数必须相同。错误 ==> oo 在 25 mx(mslen+1:length(mx))=r;
该程序是
clc;
clear all;
en=[1 0 0 0 0 0 0; ...
1 1 1 1 1 1 1; ...
1 1 0 0 0 0 0; ...
1 0 1 0 1 0 1; ...
1 1 1 1 0 0 0; ...
1 1 0 0 1 1 0; ...
0 0 0 0 0 0 0; ...
1 1 0 0 0 1 1; ...
0 0 0 0 1 1 1]
m=en;
mslen=length(m);
patlen=input('\n Enter the length of the pattern : ');
p(1:patlen)=1;
p(2:patlen-1)=randint(1,patlen-2);
mx=m;
mx(mslen+1:mslen+patlen-1)=0;
temp=mx(1:patlen);
x=patlen;
g=1;
while(x<length(mx)+1)
r(1:patlen-1)=xor(temp(2:patlen),g*p(2:patlen));
temp=r;
if x<(mslen+patlen-1)
temp(patlen)=mx(x+1);
g=r(1);
end
x=x+1;
end
mx(mslen+1:length(mx))=r;
disp(sprintf('\n\n The transmitted frame is : '));
disp(sprintf('%d',mx));
temp=0;
rx=mx;
rx(randint(1,1,[1,length(rx)]))=randint(1,1);
rx(randint(1,1,[1,length(rx)]))=randint(1,1);
temp=rx(1:patlen);
x=patlen;
g=1;
while(x<length(rx)+1)
rr(1:patlen-1)=xor(temp(2:patlen),g*p(2:patlen));
temp=rr;
if x<length(rx)
temp(patlen)=rx(x+1);
g=rr(1);
end
x=x+1;
end
disp(sprintf('\n\n The received frame is : '));
disp(sprintf('%d',rx));
if sum(rr)==0;
disp(sprintf('\n\n No error in the received frame : '));
disp(sprintf('\n\n The received data is : \n'));
disp(sprintf('%d',rx(1:mslen)));
else
disp(sprintf('\n\n Error in the received frame !!!\n'));
end