简体   繁体   English

Matlab - 多变量归一化直方图?

[英]Matlab - multiple variables normalized histogram?

I'm working on MATLAB, where I have a vector which I need to split into two classes and then get a histogram of both resulting vectors (which have different sizes). 我正在研究MATLAB,我有一个向量,我需要将它分成两个类,然后得到两个结果向量(具有不同大小)的直方图。 The values represent height records so the interval is about 140-185. 这些值表示高度记录,因此间隔大约为140-185。 How can I get a normalized histogram of both resulting vectors in different colors. 如何获得不同颜色的两个结果矢量的标准化直方图。 I was able to get both normalized vectors in the same colour (which is indistiguible) and and also a histogram with different colours but not not normalized... 我能够得到相同颜色的标准化矢量(这是不可分辨的),还有一个不同颜色的直方图,但不是规范化的......

I hope you understand my question and will be able to help me. 我希望你理解我的问题,并能够帮助我。 Thanks in advance :) 提前致谢 :)

Maybe this is what you need: 也许这就是你需要的:

matrix = [155+10*randn(2000,1) 165+10*randn(2000,1)];
matrix(1:1100,1) = NaN;
matrix(1101:2000,2) = NaN;  %// example data

[y x] = hist(matrix, 15); %// 15 is desired number of bins
y = bsxfun(@rdivide, y, sum(y)) / (x(2)-x(1)); %// normalize to area 1
bar(x,y) %// plots each column of y vs x. Automatically uses different colors

在此输入图像描述

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

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