求矩阵的模:
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
endclc;
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)