Matlab中2D矩阵元素的直方图 [英] Histogram on elements of a 2D matrix in Matlab

查看:163
本文介绍了Matlab中2D矩阵元素的直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何内置函数或一种简便的方法来绘制2d array元素的直方图.

I am wondering if there is any build in function or an easy way to plot a histogram of elements of a 2d array.

例如,如果A=rand(100,1),则A1D array,而hist(A)可以进行直方图.

For example, if A=rand(100,1), then A is an 1D array, and hist(A) can do the histogram.

但是,如果是A=rand(100,100),我想对A的元素进行直方图绘制,就像将A中的每个元素都视为1D array上的元素一样.有一个简单的方法吗?

However, what if A=rand(100,100), and I would like to make a histogram on elements of A, just like treating each element in A as an element on a 1D array. Is there a easy way to do so?

推荐答案

只需要将A整形为矢量,然后就可以照常使用hist了:

You just have to reshape A into a vector, then you can use hist as usual:

hist(A(:))

这篇关于Matlab中2D矩阵元素的直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆