matlab,直方图中的每个条形对应于哪个字母

时间:2015-06-12 20:54:54

标签: matlab histogram

我有400个文件,每个文件包含大约500000个字符,而这500000个字符只包含大约20个字母。我想制作一个直方图,表示使用的最多10个字母(x轴)和每个字母的使用次数(y轴)。我写了这个代码有缺少的东西,我想知道每个条形对应哪个字母。我应该在代码上添加什么?你可以改变整个代码,但保持这个对我来说更好。提供整个代码,以便我可以将其直接复制到脚本并运行它。

<%@ Page Title="Register" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="Register.aspx.vb" Inherits="WebFormsIdentity.Register" %>

<%@ Import Namespace="WebFormsIdentity" %>
<%@ Import Namespace="Microsoft.AspNet.Identity" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <h2><%: Title %>.</h2>
    <p class="text-danger">
        <asp:Literal runat="server" ID="ErrorMessage" />
    </p>

    <div class="form-horizontal">
        <h4>Create a new account</h4>
        <hr />
        <asp:ValidationSummary runat="server" CssClass="text-danger" />
        <div class="form-group">
            <asp:Label runat="server" AssociatedControlID="Email" CssClass="col-md-2 control-label">Email</asp:Label>
            <div class="col-md-10">
                <asp:TextBox runat="server" ID="Email" CssClass="form-control" TextMode="Email" />
                <asp:RequiredFieldValidator runat="server" ControlToValidate="Email"
                    CssClass="text-danger" ErrorMessage="The email field is required." />
            </div>
        </div>
        <div class="form-group">
            <asp:Label runat="server" AssociatedControlID="Password" CssClass="col-md-2 control-label">Password</asp:Label>
            <div class="col-md-10">
                <asp:TextBox runat="server" ID="Password" TextMode="Password" CssClass="form-control" />
                <asp:RequiredFieldValidator runat="server" ControlToValidate="Password"
                    CssClass="text-danger" ErrorMessage="The password field is required." />
            </div>
        </div>
        <div class="form-group">
            <asp:Label runat="server" AssociatedControlID="ConfirmPassword" CssClass="col-md-2 control-label">Confirm password</asp:Label>
            <div class="col-md-10">
                <asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" CssClass="form-control" />
                <asp:RequiredFieldValidator runat="server" ControlToValidate="ConfirmPassword"
                    CssClass="text-danger" Display="Dynamic" ErrorMessage="The confirm password field is required." />
                <asp:CompareValidator runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword"
                    CssClass="text-danger" Display="Dynamic" ErrorMessage="The password and confirmation password do not match." />
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <asp:Button runat="server" OnClick="CreateUser_Click" Text="Register" CssClass="btn btn-default" />
            </div>
        </div>
    </div>
</asp:Content>

1 个答案:

答案 0 :(得分:0)

首先,您使用hist是错误的。 hist(data,10)将根据包含10个bin的数据创建直方图,因此bin将对应于文件中的多个字符。

解决此问题的方法是在预定义的二进制文件上使用hist,如:

bins = 1:255; % define the bins for hist
histSum = zeros(numel(bins),1);

for file=1:10;
    data = randi(25,100) + 'a';     %Generate random data - letters between 'a' and 'z'
    data = reshape(T,numel(T),1);   % Make it a vector

    histSum = histSum + hist(data,bins)';
end

请注意,您必须定义容器以容纳所有可能的值,因此范围从1到255