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,节目是 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

节目是

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

>> 

因此,存在于kk(2)和kk(3)之间的p=24。应显示“第3帧有错误”。同样,如果p使用SPRINTF函数。由于
kk
cumsum
函数的输出,因此对其进行排序,您可以使用
find
查找帧索引

if p <= kk(end)
    idx = find((kk-p)>=0, 1);
    disp( sprintf('frame %d has error',idx) )
end
如果p=0,则为1);
disp(sprintf('帧%d有错误',idx))
结束