Editing plot pdf function to allow for changing line specification or color specification
3 次查看(过去 30 天)
显示 更早的评论
Hi, I have been using an m file that has a plot pdf function for matlab script whereby I have been able to come up with probability plots for my data. As such I have managed to compute the required plots however I have been unable to specify a line type or color as the function does not recognise this properties. The script file is relatively old and as such I do not have enough time to edit the whole function due to my limited knowledge in Matlab. The relative code for the script file is listed below: function [pdf_out, x_out] = pdf(in,bin)
% PDF ......... computes and plots the sample probability density function.
%
% PDF(X) plots the sample pdf of the input vector X with 100
% equally spaced bins between the minimum and maximum
% values of the input vector X.
% PDF(X,N), where N is a scalar, uses N bins.
% PDF(X,N), where N is a vector, draws a pdf using the bins
% specified in N.
% [f,x] = PDF(...) does not plot the pdf, but returns vectors
% f and x such that PLOT(x,f) is the sample pdf.
% Darius Communications, April 1996
% Updated for Matlab 5, February 1998
%------------------------------------------------------------------------
% Define parameters
%------------------------------------------------------------------------
nx_default = 100;
axis_default = 1;
%------------------------------------------------------------------------
% Prepare absicca vector and other parameters
%------------------------------------------------------------------------
if ((nargin ~= 1) & (nargin ~= 2))
error(eval('eval(BELL),eval(WARNING),help pdf'));
return;
end
if (nargin == 1)
nx = nx_default;
max_x = nx_default;
else
nx = bin;
end
max_y = length(in);
[out,x] = hist(in,nx);
nx_aug = [x,x(length(x))+(x(length(x))-x(length(x)-1))];
if ( length(out(out~=0)) <= 10 ) % Discrete distribution
out = out/max_y ;
flag = 'discrete';
else % Continuous distribution
out = (out ./ diff(nx_aug))/max_y ;
flag = 'continuous';
end
%------------------------------------------------------------------------
% Output routines
%------------------------------------------------------------------------
if (nargout == 0)
axis_default = (max(x) - min(x))/2;
xmin = min(x)-axis_default; xmax = max(x) + axis_default;
if strcmp(flag, 'discrete')
delta = max(diff(x));
nbin = length(x);
xa = [ (x(1)-delta/2), (x+delta/2) ];
oa = [ out(1), 0, out(2:nbin) ];
stairs(xa,oa), ...
grid on, ...
if( strcmp(axis('state'),'auto') ), ...
axis([xmin xmax 0 1.5*max(out)]); end; ...
title('Sample PDF')
elseif strcmp(flag, 'continuous')
plot(x,out), ...
grid on, ...
if( strcmp(get(gca,'DataAspectRatioMode'),'auto')), ...
axis([xmin xmax 0 1.5*max(out)]); end; ...
title('Sample PDF')
end
elseif (nargout == 1)
pdf_out = out;
else
pdf_out = out;
x_out = x;
end
The code is based on a really old version of Matlab however it does a good job in producing probability plots relatively easily without the need to specify the distribution which is very helpful in my data analysis. As such if possible what aspect of the code should I change or improve in order to input 'linespecification' or 'color specificaton' in the plotpdf option.
0 个评论
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!