matlabマトリクス、ベクトルのモードを求める

926 ワード

行列の型を求める:
function count = juZhenDeMo(a,b)
[r,c] = size(a);% a   
[r1,c1] = size(b);% b   
count = 0;
for j=1:r-r1+1%       
    for i=1:c-c1+1%       
        d = a(j:j+r1-1,i:i+c1-1);
        e = double(d==b);
        if(sum(e(:))==r1*c1)
            count = count + 1;
        end
    end
end
clc;
clear;
a = eye(6)
b = [1 0;0 1]
disp('a   b      :');
count = juZhenDeMo(a,b)

end
 
  

function count = sta_submatrix1(a,b)
count = 0;
for i = 1:length(a)-length(b)+1
    c = a(i:i+length(b)-1);
    e = double(c==b);
    if(sum(e) == length(b))
        count = count + 1;
    end
end
end
clc;
clear;
a = [0 0 0 1 0 0 1  0 0 1 0 0 1 0 0]
b = [0 0 ]
disp('b a       :')
count = sta_submatrix1(a,b)