该程序是
clc;
clear;
d =input('enter the hop count of all path'); % [ 1 2 3]
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]
c = cumsum(d); % [1, 3, 6]
s = ceil(size(en,1)*c/c(end)); % [2, 5, 9]
n = [s(1) diff(s)]; % [2, 3, 4]
B = mat2cell(en, n, size(en,2));
n=1;
for i=1:length(d)
disp(sprintf('the transmiting frame thr path %d ',n));
disp(B{i});
n=n+1;
end
disp ('SINGLE BIT ERROR');
S=randint(1,1,[1,size(en,1)]);
T=randint(1,1,[1,size(en,2)]);
if (en(S,T)==1)
en(S,T)=0;
elseif (en(S,T)==0)
en(S,T)=1;
end
disp(en);
disp('SINGLE BIT ERROR INTRODUCED AT');
disp(S); %row
disp(T); % column
p=S*T;
disp('error at bit');
disp(p); %displays which bit is error
for i=1:length(d)
disp(sprintf('size of transmitted frame %d',i));
disp(size(B{i})); % size of each transmitted frame
ee(i)=(size(B{i},1)*size(B{i},2));
end
disp('display (row*column) of each frame');
disp(ee(:)); % displays (row*column) of each frame
kk=cumsum(ee(:));
disp('the cumulative sumation is ');
disp(kk); % cumulative sumation of the elements in ee
输出将是
enter the hop count of all path[ 1 2 3]
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
the transmiting frame thr path 1
1 0 0 0 0 0 0
the transmiting frame thr path 2
1 1 1 1 1 1 1
1 1 0 0 0 0 0
the transmiting frame thr path 3
1 0 1 0 1 0 1
1 1 1 1 0 0 0
SINGLE BIT ERROR
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 1 1
1 1 1 1 0 0 0
SINGLE BIT ERROR INTRODUCED AT
4
6
error at bit
24
size of transmitted frame 1
1 7
size of transmitted frame 2
2 7
size of transmitted frame 3
2 7
display (row*column) of each frame
7
14
14
the cumulative sumation is
7
21
35
>>
因此 p=24 存在于 kk(2) 和 kk(3) 之间。它应该显示“第 3 帧有错误”。同样,如果 p<=kk(1),它应该显示'第 1 帧有错误',如果 p 在 kk(1) 和 kk(2) 之间,它应该显示'第 2 帧有错误'。但是长度 (d) 会随着用户的输入而相应变化。我无法像这样显示它。请帮我。