Reputation: 2689
Im creating histograms using two scripts, one is matlabs own hist
function and another is a script I downloaded. The script I downloaded takes the absolute min and max values and generates a histogram between that. But the issue is that unlike MATLAB, this histogram is not displayed. I am presented with a vector.
Now to compare the two visually I am using plot
, but for some reason the scale changes. For example histogram using MATLAB's hist
is shown below:
And if I show this histogram in plot
, the x-axis scale changes:
How can I keep the scale same?
I need this because the downloaded script does not generate the histogram so to display it I use plot
. Again the plot is between 0 and 100 and I feel this may not be an accurate comparison
Upvotes: 2
Views: 1509
Reputation: 71
Use "n = hist(Y,x) where x is a vector, returns the distribution of Y among length(x) bins with centers specified by x", to specify the bins centers.
Upvotes: 3
Reputation: 24179
It seems that you're not using all the available information at your disposal. Please see the code below for an example of how what you want can be done:
%% Generate some data:
rng(42653042);
data = randn(300); data = (data-min(data(:)))*90+100;
data(1:4:end) = data(1:4:end)/2;
%% Plot using hist:
figure(); hist(data(:),100);
%% Return bin info using hist:
[N,X] = hist(data(:),100);
%% Plot the other function's output w/o X:
figure(); plot(N);
%% Plot the other function's output w/ X:
figure(); plot(X,N);
figure(); bar(X,N);
The function hist
should be replaced in newer versions of MATLAB by:
histogram
, when used for plotting (i.e. the case of hist
without outputs).histcounts
, when used for counting (i.e. the case of hist
with outputs).Upvotes: 4