How can i edit this histogram code to allow it to go onto only one plot
8 views (last 30 days)
Show older comments
I am plotting this currently and the 2 plots i have get mashed into one plot how can i use my handles.axes5 to only make this go to this axes
function pd1 = createFit(data)
%CREATEFIT Create plot of datasets and fits
% PD1 = CREATEFIT(DATA)
% Creates a plot, similar to the plot in the main distribution fitting
% window, using the data that you provide as input. You can
% apply this function to the same data you used with dfittool
% or with different data. You may want to edit the function to
% customize the code and this help message.
%
% Number of datasets: 1
% Number of fits: 1
% This function was automatically generated on 24-Feb-2012 11:04:17
% Data from dataset "data data":
% Y = data
% Force all inputs to be column vectors
data = data(:);
% Prepare figure
clf;
hold on;
LegHandles = []; LegText = {};
% --- Plot data originally in dataset "data data"
[CdfF,CdfX] = ecdf(data,'Function','cdf'); % compute empirical cdf
BinInfo.rule = 1;
[~,BinEdge] = internal.stats.histbins(data,[],[],BinInfo,CdfF,CdfX);
[BinHeight,BinCenter] = ecdfhist(CdfF,CdfX,'edges',BinEdge);
hLine = bar(BinCenter,BinHeight,'hist');
set(hLine,'FaceColor','none','EdgeColor',[0.333333 0 0.666667],...
'LineStyle','-', 'LineWidth',1);
xlabel('Data');
ylabel('Density')
LegHandles(end+1) = hLine;
LegText{end+1} = 'data data';
% Create grid where function will be computed
XLim = get(gca,'XLim');
XLim = XLim + [0 1] * 0.01 * diff(XLim);
XGrid = linspace(XLim(1),XLim(2),100);
% --- Create fit "fit 2"
% Fit this distribution to get parameter values
% To use parameter estimates from the original fit:
% pd1 = ProbDistUnivParam('normal',[ 680773080421.6, 536136932045.3])
pd1 = fitdist(data, 'normal');
YPlot = pdf(pd1,XGrid);
hLine = plot(XGrid,YPlot,'Color',[1 0 0],'LineStyle','-', 'LineWidth',2,'Marker','none', 'MarkerSize',6);
LegHandles(end+1) = hLine;
LegText{end+1} = 'fit 2';
% Adjust figure
box on;
hold off;
% Create legend from accumulated handles and labels
hLegend = legend(LegHandles,LegText,'Orientation', 'vertical', 'Location', 'NorthEast');
set(hLegend,'Interpreter','none');
0 Comments
Answers (2)
Image Analyst
on 24 Feb 2012
It looks like that the code for createFit() acts upon only the current figure. So you need to make your handles.axes5 the current figure. So before you call that function, issue this command:
axes(handles.axes5);
That will make handles.axes5 the current figure and anything createFit() does should happen inside handles.axes5.
3 Comments
Walter Roberson
on 25 Feb 2012
You can't make an axes the current figure -- but you can make it the current axes, which is what is required (as well as getting rid of the clf call)
Image Analyst
on 25 Feb 2012
Yeah, that's what I meant - just got imprecise with my terminology. Thanks for the correction.
Walter Roberson
on 25 Feb 2012
Your question is not clear. The code you show uses only a single axes, so it will all appear on one plot.
If your question is how to get this output to appear on an existing plot, then remove the clf() from the code, and use the axes() call before calling this routine as Image Analyst discusses.
2 Comments
See Also
Categories
Find more on Graphics Object Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!