0

我有一个大小为 1x1000 的矩阵。如何绘制此随机数据的直方图。我无法应用hist命令,因为它不需要。箱。如何决定不。当输出是这个矩阵时的 bins。它的直方图和pdf的性质是什么。

m_SIR_SU =

  Columns 1 through 12

    3.1143   12.8266  -10.4597   20.8193    1.2036   22.1917   16.6404   -2.1747   14.7870   -0.1750   17.9230   21.6503

  Columns 13 through 24

   22.6298    8.8368   -7.5701   -9.1480   24.8008   25.2241    5.1497   10.1364   20.6523   13.5170   24.3638   22.8368

  Columns 25 through 36

   -4.0256    3.4712   24.8473   20.3856    9.8586    7.9472    3.6841   22.6547    9.5229   23.6298    1.7185   -2.3464

  Columns 37 through 48

   18.2688    6.2398   15.1851   12.0138   16.8261    5.0790   17.2463   12.8158   13.5059    3.3817   19.7647  -10.6391

  Columns 49 through 60

   23.0559    7.2573   19.7791    9.7403   22.3583   21.8934    9.8713   12.7451    7.4452   17.5498   12.4172   -4.9624

  Columns 61 through 72

  -15.2914   15.8457   12.4343   19.4865  -10.8145   22.3592   -5.7041    3.0798   13.9808   23.8388   18.1387   21.8099

  Columns 73 through 84

    1.4490   20.8895   12.9483   11.8998   -6.2724    8.1395    6.6716   24.6358   -1.0938   24.5365   12.4058   -2.0318

  Columns 85 through 96

  -10.0411   -1.5261   23.0585   -7.3129   12.1013   19.7631   21.9379    6.5803   15.3412   23.0485  -19.7686   14.6987

  Columns 97 through 108

    4.8440   14.0121    0.2701   19.5125   10.9891   19.9954   21.8048   24.3611    4.8377   15.3876   -3.7644   18.6335

  Columns 109 through 120

   -8.2429   14.1494   16.2510   19.8763   -4.2530   22.2335   15.6233   13.4121  -14.3926   19.9585   18.9019   17.9961

  Columns 121 through 132

    9.9310   22.5066   20.8492   20.7201    3.7406   -1.1431   19.6511   13.4896   22.0894   -7.2231   18.3995    4.5214

  Columns 133 through 144

   -1.2212   17.7128   16.9634   19.0148    2.1982   20.5636   22.8517   19.1908   21.9122   19.5032   12.9961   18.5094

  Columns 145 through 156

   13.9744   18.4371   -4.1708   15.9433   19.2935   18.6221    3.4737    8.6776   17.9156    5.9932    2.8915   24.7065

  Columns 157 through 168

   -3.5831   17.9418   16.0072    2.6069   20.2114   23.3133   20.8495    9.8424   14.4864   24.0575   13.1039   23.5231

  Columns 169 through 180

   -1.1074   -9.5503   12.8528   18.4714    3.6147    9.4028    8.2549  -29.1474   18.5855   -1.9708   14.4915   10.0668

  Columns 181 through 192

    9.1886   18.4410   12.5856    5.3606   24.3115   -3.1107    4.7734   16.4518  -11.5257   12.7726   10.3782   24.1398

  Columns 193 through 204

   16.5187   -3.6252   18.5054    7.7256    7.7233   16.9101    4.0459  -11.3605   21.8611   15.2621   14.5121   15.3325

  Columns 205 through 216

    7.9852   22.8393  -10.4399   -3.8988   22.6575   13.4566   -3.7922   -3.0905   10.5690   -0.4155    0.7602   12.1940

  Columns 217 through 228

   16.3045   22.2269  -13.0022   19.6432   13.7388   23.3205   14.3952   12.3955   16.0980    4.5279  -13.1766    9.4957

  Columns 229 through 240

   -2.4867   18.6075   -0.2416   14.8591   -3.8525   22.5614   -3.9405  -15.7647  -17.7263   22.5830   19.4998   16.8518

  Columns 241 through 252

   24.4494    7.2578   23.2791   19.2177   21.6955   16.0310   22.3782   13.3570    6.8531    5.9008   -9.9231   19.8152

  Columns 253 through 264

   10.4352   12.3101  -19.7597   -4.8294    4.9557   -4.5681   18.3188   20.5055   17.1743   19.0657   21.2414    8.5090

  Columns 265 through 276

  -13.9360   12.5057   24.7137   16.6343   18.1940    3.2008   12.2830    9.7005   23.8997    3.2054  -18.2804   23.5466

  Columns 277 through 288

    4.6165  -12.0288   14.5694   -6.8659   16.3960    8.1170    7.6458   12.7286   11.9851    7.3085   16.3672    9.7813

  Columns 289 through 300

   20.7130    8.9363   21.6058   -7.7229   24.9194   14.1539   13.1019   17.6225   -1.0509   22.5234    9.3373   15.0910

  Columns 301 through 312

   12.4383    8.7756    9.5229   -1.2958    8.7990   -1.1887   13.1662   24.3292    5.9338   17.8945   10.3812   12.0542

  Columns 313 through 324

   -2.1154   -4.4908   22.5672   23.8202   23.2760    9.8215    4.7731   -7.4138  -10.1916    9.7824    4.7400   24.0828

  Columns 325 through 336

    6.4175    3.1476    7.1783   14.4256    3.8791   22.4789    6.1857   22.2562    2.1091   24.5908   19.1568   -3.7121

  Columns 337 through 348

   23.0053   20.2116   13.5992   24.2402   19.0291   13.1637   20.2883   20.6765   -3.3210   19.7126   22.5609   22.3013

  Columns 349 through 360

   21.8918   17.1509   -5.8178   14.1786   19.3950   21.9774  -14.6555   -1.5641   10.7374   -0.5795   18.7736   23.4023

  Columns 361 through 372

   21.2085   11.4272   13.2664   23.3330   -4.5078    4.6153   16.4786   14.2271   22.9317   16.3172    3.5742   18.0425

  Columns 373 through 384

   21.0778   10.2545   24.3502   23.8587  -19.4650   -6.0176   16.2508    9.2197  -47.8908    8.2188   17.2284   20.0619

  Columns 385 through 396

   22.3382   14.3910   21.5147  -16.6395    9.1265   14.4265   16.4529   19.2864  -30.7454   23.7049   -4.7053   17.1816

  Columns 397 through 408

   20.9988    3.0436   -5.7028   -3.2404   16.6604   20.0256   -4.5528   22.2362   21.5977   23.7955   11.6178   19.8688

  Columns 409 through 420

   20.2853   17.5979    8.0503   20.5221    9.9057  -12.3146   13.0926   14.1138    0.5834   -9.2024   15.4738   22.5113

  Columns 421 through 432

   15.4683   19.6569   11.8542   17.9246   11.0744   13.8646   23.4753   -1.1463   20.1015    6.2268   10.0964   -8.5307

  Columns 433 through 444

   17.3651  -13.2540    2.1768   18.9061   21.5442   23.9051   19.5728   11.5393   14.7571   13.6199    7.2314  -10.9265

  Columns 445 through 456

   23.4076   20.7657  -11.2402    6.0154   -2.1196    5.7117   -0.0119   15.1974   24.0591   15.5617   12.7281   11.9834

  Columns 457 through 468

   16.6351  -22.2521  -14.2090   10.3872  -32.4577   24.3754  -20.1414   22.6486   12.5268   23.7598   16.4683   25.1559

  Columns 469 through 480

    7.0257   14.9243  -10.5469   16.7565    8.2584   21.1107   18.9832   23.0607    3.5011   21.1802   12.7810   21.0219

  Columns 481 through 492

   -9.6787   23.7891   -3.1141   16.1979   20.8157   11.2932    8.0996   19.9793   12.8104   10.9255   -5.7119   20.0756

  Columns 493 through 504

   19.7699   15.0674   21.6674    5.6487   10.3777   15.0335   24.1197   18.8044    3.3881   10.7781    4.0454    5.1816

  Columns 505 through 516

   21.1144   10.5409   13.4258    4.1279   21.8084   17.4903    7.9033   18.1242   13.6821    7.8551   14.6067    3.1478

  Columns 517 through 528

   10.0707    8.6723   16.2126   14.4863   12.1799   22.6394   20.5864   -4.5133   19.7107   17.3046   18.1358  -17.3852

  Columns 529 through 540

    6.0937    2.3090   -0.2220    1.5995    6.1170    9.6396   -2.9612    6.6696   15.8229   19.6982    3.4762   21.1814

  Columns 541 through 552

   -5.0250   23.6460   25.8105    1.7277   11.6052   17.6773   -7.2448    7.2158   17.0813   21.8725  -11.4134    6.8135

  Columns 553 through 564

    2.3845   22.3122   16.1726  -11.8366    7.4094  -18.3545   16.8456   17.7031   -1.0107  -12.2803   12.4227   18.4426

  Columns 565 through 576

   21.1181   16.4937   19.0667    6.1154   -7.5398  -17.0356   11.0205   19.4845   17.3708   12.6848   21.3559   25.2790

  Columns 577 through 588

   24.4583   -3.0867   -0.5439   11.7985   22.1316   22.9560    3.9956   20.1440   11.5224    5.1242   -7.0063   12.3645

  Columns 589 through 600

   10.7339   20.2418    4.4879   11.9179   -1.6820   19.5576    4.4135   12.6833   14.0107   19.0557   16.7520   13.7658

  Columns 601 through 612

   22.2472   24.0167    6.5646   15.9701   -5.6276   23.2256   -1.5661   17.9403  -19.5608    5.8429   20.4147   12.9571

  Columns 613 through 624

   13.1610   13.9334   -7.9791   13.2914   23.3541   -2.3087   22.6658   11.8415   15.6788   11.8079   11.6546    4.1837

  Columns 625 through 636

    0.5525   14.1287    4.5229   11.1840   19.0459    8.6573    3.1802    7.9893    6.4692   10.5290   -1.9341   24.7597

  Columns 637 through 648

   14.8639    3.2738   10.8049   23.9817   -5.8366   24.3834   13.4359    4.2490   21.9847   -9.1489    7.9476   20.2561

  Columns 649 through 660

   15.0094   21.3259    9.2039   -1.6139   23.1399   -1.2675    9.0426   16.8943   13.0709   16.4847    6.6746   20.4594

  Columns 661 through 672

   24.8421   -1.4786   10.6748   17.2364    8.7116   21.1113   23.7438   18.6245   21.8692    0.0460   14.5536   22.4841

  Columns 673 through 684

   21.7918  -10.6537   11.2333    4.5613   10.5894  -24.0947   10.3594   10.2981   22.7324    2.5822   -2.4210   22.6202

  Columns 685 through 696

    3.2856   23.3656   16.8861    8.3809   24.7985   21.2383    1.3542    6.1350   21.7415   25.1190   20.3096    4.3156

  Columns 697 through 708

   22.2033   14.6346   12.6396    1.4612    7.2545   -8.3392    7.7333    8.3409   11.6267   -1.7724   19.2836   22.1828

  Columns 709 through 720

   12.3172    7.3262    0.8337   13.3511   11.7651   -6.4826   24.4986   20.4363   14.4714   19.6669   17.0340   20.7079

  Columns 721 through 732

    0.2035    0.1110   24.0248  -18.0660   11.0757    2.9405    2.9377  -20.2975   16.8046   10.5980   15.9038    3.8560

  Columns 733 through 744

   11.9366   15.9228   22.0819   16.9803    1.5006    9.5806  -12.6343   11.4400   19.4007   12.3847   17.6381   10.9586

  Columns 745 through 756

   20.5678   12.7918   -2.2205   10.1368   12.3443   20.9106   20.6848   17.6225   16.3257    3.1674    7.1777   17.0709

  Columns 757 through 768

  -13.1589   11.0551   -2.1184   23.3110   12.1927  -30.8428  -16.6259    8.6530    0.4595   21.4808   15.5965    4.4974

  Columns 769 through 780

    6.4492    4.7020   24.6517    8.3413    4.4613   22.3309   13.4146   25.0251    0.0619   17.4230  -12.5809    9.9662

  Columns 781 through 792

   17.4419    9.4654   15.6600   14.9352   13.1798    9.2061   -5.9166   16.5305   24.0777    9.4214   -3.8586   24.4610

  Columns 793 through 804

  -22.3023    4.0220    8.0413    4.5141   17.8212   21.8239    7.0066   19.2048    9.3079   12.4533  -11.2369  -22.1634

  Columns 805 through 816

   14.0394   -2.5475   17.8827   10.1856    3.1175   17.5539   23.0894   22.9427   10.6805   21.7780   10.4405   18.5549

  Columns 817 through 828

   23.4421    5.4531   10.5287   18.8985    2.5515   23.7638    4.4745   -9.4263   24.0055   -7.0340  -21.8509   13.6929

  Columns 829 through 840

   13.2776   13.4972   10.0714    2.8182   13.2393   -9.8101   18.7226   11.2005   12.0190   12.5419   13.4739   14.0413

  Columns 841 through 852

    2.2810    9.0674   18.1518  -24.6664   10.0668   19.7481    2.0905   11.6921   23.0575   14.1509   17.5971    1.9482

  Columns 853 through 864

   -5.9919   20.5882  -10.1625    3.9253    5.7599    9.7138   -3.0538   19.6938   16.8113   23.3448   21.8296    5.8226

  Columns 865 through 876

   17.6925  -16.2738   15.5973    1.1930   22.2721   11.4343   23.4930   20.2491   22.5872    0.8353   16.8785   16.8523

  Columns 877 through 888

    3.3807   23.7515    6.6763   23.3247    9.5512  -11.9353   20.2654    6.4631  -32.0256   19.1966    9.5994   24.1581

  Columns 889 through 900

    5.0054    7.7977    7.1539   -6.8754   12.1732  -13.8509    9.1757   12.4463   22.9073   21.5420   -5.8633   21.0112

  Columns 901 through 912

   13.2941   14.2776    9.4999   17.1849    8.4598    8.7673   17.1714    4.3529  -24.7716   15.9223   11.4322   14.3806

  Columns 913 through 924

   22.5852    6.6638   20.4638   22.3946   22.6033   -5.6090    7.9896  -10.6873   20.9147  -14.5063    1.0616   18.7306

  Columns 925 through 936

    7.0097   23.0482   10.9954   -2.8075   25.7660   20.7874    0.3680   21.4917   -6.6140    5.9869   21.0128    5.1931

  Columns 937 through 948

   23.4153   -6.8217   13.9697   24.4942   20.1318   18.4823   19.4630   -5.8234    6.1744   21.5543  -16.6184    2.0871

  Columns 949 through 960

    4.4450   -8.1314   22.0302   18.8161    5.2294   23.9193   12.0840   17.4780   17.6119    8.8761   -6.6852   23.2893

  Columns 961 through 972

   23.4560   14.9606    5.8889   22.9689   18.0416   19.9161   -4.6528  -26.2008   23.6307   23.0924    7.2145   -8.4485

  Columns 973 through 984

   21.3776    4.1225   -2.0679   12.3074    3.0664    4.2298   20.3053   13.4311   16.2094   24.3459   18.0053   21.0069

  Columns 985 through 996

    4.7273   -8.8592   24.4293   18.9754   -7.3654    7.7107   23.2117    8.2289   22.8241   19.7715   12.0123   11.1991

  Columns 997 through 1000

   14.5318    8.2633    8.3647   20.6225
4

2 回答 2

1

您必须自己决定垃圾箱的数量。

[n x] = hist(x);
bar( x, n ); %plot
pdf = n/sum(n);

看到相关的这个问题

于 2013-05-13T19:59:07.997 回答
0

取决于你想要的粒度。我的直方图经验来自于进行照片分析和从图像生成颜色和亮度直方图 - 所以我通常有更多数据需要处理,而且我已经知道我的界限(上限和下限)。

对于 1000 点,100 个桶可能太多了,但 20-50 可能就可以了。因此,搜索最小值和最大值的数据,使用它为每个存储桶创建适当的边界,然后循环遍历数据,增加相关存储桶上的计数器。

就像是:

    class MyHistogram
    {
        int[] _histogram;

        public void MyHistogram(int bucketCount, double[] data)
        {
            double minValue = data[0];
            double maxValue = data[0];

            for(int i=0;i<data.Length;i++)
            {
                if (data[i] < minValue) minValue = data[i];
                if (data[i] > maxValue) maxValue = data[i];
            }

            double bucketSize = (maxValue - minValue) / bucketCount;
            _histogram = new int[bucketCount];

            for (int i = 0; i < data.Length; i++)
            {
                int bucket = (int)((data[i] - minValue) / bucketSize);
                _histogram[bucket]++;
            }
        }

        public int[] Histogram { get { return _histogram } }
    }
于 2012-11-29T06:58:11.027 回答