法一:假定要分析的矩陣為data,
x=data(:)
x=sort(x);
d=diff([x;max(x)+1]);
count = diff(find([1;d])) ;
y =[x(find(d)) count]
最後輸出的y(1)為元素值,y(2)為所對應的元素值在此矩陣中的出現的次數
法二:
>> A = [1 3 5 3 1 5 3 1 1 3 5];
>> count = hist(A,unique(A))
count =
4 4 3
法一:假定要分析的矩陣為data,
x=data(:)
x=sort(x);
d=diff([x;max(x)+1]);
count = diff(find([1;d])) ;
y =[x(find(d)) count]
最後輸出的y(1)為元素值,y(2)為所對應的元素值在此矩陣中的出現的次數
法二:
>> A = [1 3 5 3 1 5 3 1 1 3 5];
>> count = hist(A,unique(A))
count =
4 4 3