限制在MATLAB直方图中显示的数据值 [英] Limit data values displayed in MATLAB histogram

查看:439
本文介绍了限制在MATLAB直方图中显示的数据值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个向量,我想为其打印数据的直方图.此数据的范围是-100到+100.外边缘周围的数据量微不足道,因此我不想看到它.我最感兴趣的是显示从-20到+20的数据.

I have a vector that I want to print a histogram of of data for. This data ranges from -100 to +100. The amount of data around the outer edges is insignificant and therefore I don't want to see it. I am most interested in showing data from -20 to +20.

1.)如何限制该窗口在直方图上打印?

1.) How can I limit that window to print on my histogram?

我在0处的数据量比我在数据集中任何地方的数据量至少少10:1.当我打印直方图时,元素频率的布局会丢失,因为它的数量比0多.

The amount of data I have at 0 outnumbers of the amount of data I have anywhere in the dataset by a minimum of 10:1. When I print the histogram, the layout of element frequency is lost because it is outnumbered by 0.

2.)有没有一种方法可以将0值的数量缩放为-1项的数量的三倍?

2.) Is there a way that I can scale the number of 0 values to be three times the number of -1 entries?

我期望这个数据集呈指数下降(通常),因此,频率为-1的三倍会很容易让我看到其他数据的频率.

I am expecting an exponential drop of this dataset (in general) and therefore three times the frequency of -1 would easily allow me to see the frequency of the other data.

推荐答案

1)您可以通过设置X轴限制来限制在图表上看到的直方图范围:

1) You can limit the histogram range you see on the plot by just setting the X axes limits:

xlim([-20 20])

在hist命令中设置bins很好,但是请记住,bins之外的所有值都将落入最左侧和右侧的bin中.因此,您仍然需要设置轴限制.

Setting bins in hist command is good, but remember thatall the values outside the bins will fall into the most left and right bin. So you will need to set the axes limits anyway.

2)如果不同容器中的值之间存在很大差异,则一种方法是将Y轴上的值转换为对数刻度.不幸的是,仅将Y轴设置为对数(set(gca,'YScale','log'))不能用于条形图.用histhistc(取决于您要指定垃圾箱的中心还是边缘)计算直方图,并将值log2:

2) If there is a big difference between values in different bins, one way is to transform values on Y axes to log scale. Unfortunately just setting Y axes to log (set(gca,'YScale','log')) does not work for bar plot. Calculate the histogram with hist or histc (depending on whether you want to specify bins centers or edges) and log2 the values:

[y, xbin] = hist(data);
bar(xbin, log2(y) ,'hist')

这篇关于限制在MATLAB直方图中显示的数据值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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