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
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 (ie the case of hist
without outputs). histcounts
, when used for counting (ie the case of hist
with outputs). 使用“n = hist(Y,x),其中x是向量,返回长度(x)区间中Y的分布,其中心由x”指定,以指定区间中心。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.