谁会做这个MATLAB啊。很急

来源:百度知道 编辑:UC知道 时间:2024/05/16 19:40:52
实现函数function [n]=matchCount(A,num)
A为一个矩阵,num为一个数字
要求这个函数计算这个num 在A中作为矩阵元素出现的次数

function n=matchCount(A,num)
[a b]=size(A)
s=0
for i=1:a
for j=1:b
if A(i,j)==num
s=s+1;
end
end
end
s
%s为num出现的个数

function n=matchCount(A,num)
length(find(A==num));

%例如
A=[ 8 2 6
3 2 7
4 9 2];
num=2;
matchCount(A,num)

ans =

3