【问题标题】:equally spaced "histogram" in MatlabMatlab中等距的“直方图”
【发布时间】:2021-08-16 15:23:30
【问题描述】:

我有一个数字向量,比如说 v=[1 1 1 1000 20 20];我想构建非常简单的类似直方图的图,其中 y 轴将被计数(在本例中为 3,1,2),但 x 轴将等间距为 1,20,1000。这意味着 Matlab 将忽略 1000>>20 并将它们间隔为情节中的 1,2,3 的事实。 我会证明我的意思。我可以这样做:

x=[1 1 1 1000 20 20];
histogram('Categories',{'1','20','1000'},'BinCounts',[numel(find(x==1)), numel(find(x==20)), numel(find(x==1000))])

但这有点笨拙和笨拙。我必须事先知道类别。可以用更优雅的方式完成吗?

【问题讨论】:

  • “更优雅”的意思是你只想删除硬编码的类别和find(x==*)

标签: matlab histogram


【解决方案1】:

首先将 X 转换为分类矩阵 convert to categorical 然后 histogramplot X 具有以下类别: plot categorial histogram

如果您遇到问题:

C = categorical(x,[1 20 1000],{'1','20','1000'})
//or just C=categorical(x,[1 20 1000]) or simply C=categorical(x)
histogram(C)

【讨论】:

  • 就这么简单?...我不知道“分类”函数,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-04
  • 1970-01-01
  • 2013-01-17
  • 1970-01-01
  • 1970-01-01
  • 2011-01-23
  • 2013-02-14
相关资源
最近更新 更多