histfit, Reusing matlab auto generated code.

2 次查看(过去 30 天)
Hi,
I am trying to get histfit plot for a vector. First i am using MATLAB plot tool to get required pot. But i want to use this in a loop so thats why i have generated m-code from ==> File ==> Generate M-File.
Problem is I don't get how to use it. Here is a short example:
v = [1:20];
histfit(v);
Here I get a plot, then go to File and generate M-file. After that i got following code:
function createfigure1(xvector1, yvector1, X1, Y1)
%CREATEFIGURE1(XVECTOR1,YVECTOR1,X1,Y1)
% XVECTOR1: bar xvector
% YVECTOR1: bar yvector
% X1: vector of x data
% Y1: vector of y data
% Auto-generated by MATLAB on 15-Mar-2011 14:36:01
% Create figure
figure1 = figure;
% Create axes
axes1 = axes('Parent',figure1);
box(axes1,'on');
hold(axes1,'all');
% Create bar
bar(xvector1,yvector1,'BarWidth',1);
% Create plot
plot(X1,Y1,'LineWidth',2,'Color',[1 0 0]);
Now the problem is if i wanna use this function then i have to give 4 input arguments and I need your help in that. Because in first step i was using just histft(v). So how to get these 4 input arguments from v.
Thanks in advance.
\\Arsalan

采纳的回答

Kaustubha Govind
Kaustubha Govind 2011-3-15
Here's one way of doing it:
h=histfit(v);
xvector1 = get(h(1), 'XData')
yvector1 = get(h(1), 'YData')
X1 = get(h(2), 'XData')
Y1 = get(h(2), 'YData')
createfigure1(xvector1, yvector1, X1, Y1)
Albeit, roundabout.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by