简体   繁体   English

MatLab-按矩阵列获取直方图

[英]MatLab - Obtain histogram by column of matrix

Simply put I have an N x M matrix and I would like to obtain a 256 bin histogram for each column of the matrix. 简而言之,我有一个N x M矩阵,我想为矩阵的每一列获取256 bin直方图。 I know how to do this with a for loop, but I need to do it in matrix notation to save valuable computation time. 我知道如何使用for循环执行此操作,但是我需要以矩阵表示法执行此操作,以节省宝贵的计算时间。

Also, I would like to use imhist rather than hist. 另外,我想使用imhist而不是hist。

For loop method: 对于循环方法:

data = randint(100,100,10); 数据= randint(100,100,10);

for n = 1:100 对于n = 1:100

k(:,n) = imhist(data(n,:));

end 结束

hist operates on the column of the input matrix by default. hist默认情况下对输入矩阵的列进行操作。 So 所以

>> k = hist( data, 0:255 ); 

should do the trick for you. 应该为您解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM