matlab求矩阵、向量的模
求矩阵的模:
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<pre name="code" class="plain">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)
每当夜深人静的时候,想想今天发生了什么,失去了什么,得到了什么,做了什么,没做什么,该做什么,不该做什么,明天要做什么!

浙公网安备 33010602011771号