Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The form of the function that you're using (<code>hist(data,1000)</code>) means that 1000 bins are generated, and MATLAB is defaulting to sizing them with a width of 1 because it has no information about the range of the data (a single value doesn't have a meaningful range). Here's a blurb from the <a href="http://www.mathworks.com/help/matlab/ref/hist.html" rel="nofollow">documentation</a>:</p> <blockquote> <p>n = hist(Y,nbins) where nbins is a scalar, uses nbins number of bins.</p> </blockquote> <p>There are a few options that could make it "better" (in quotes, because nobody but you knows what you want):</p> <p>1) You could use a different form of the function to specify where the bins should be:</p> <blockquote> <p>n = hist(Y,x) where x is a vector, returns the distribution of Y among length(x) bins with centers specified by x. For example, if x is a 5-element vector, hist distributes the elements of Y into five bins centered on the x-axis at the elements in x, none of which can be complex. Note: use histc if it is more natural to specify bin edges instead of centers.</p> </blockquote> <p>2) You could limit the number of bins to the number of elements in the data vector, if less than some minimum value:</p> <pre><code>hist(data, min(1000, numel(data))) </code></pre> <p>3) You could check for special cases (like N=1) - you mention that this is not desirable, but using a script/function this isn't a hardship at all, so you may have to clarify why this isn't acceptable.</p> <p>4) You could scale the x-axis appropriately after plotting (similar to @Parag's answer)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload