difittool工具
- matlab命令行输入dfittool调出工具窗口
- 加载数据后直接选择PDF或CDF函数就可以。具体使用可参考帮助文档
效果图如下:
-
由界面生成代码
在界面上调整坐标轴不是很方便,我至今未找到在哪调整。转换成figure再进行调整,一次还行,如果有很多的数据,每次都要去调就会显得很麻烦。解决办法:点击界面文件中的自动生成代码。通过代码调整,不仅方便,还可以查看它到底是怎么实现的,另外还能学到一些设置坐标轴的办法等,用处多多。
下面以一个简单的实例来一探究竟。
结果示例1
上图对应生成的代码如下:
function createFit(arg_1,arg_2)
%CREATEFIT Create plot of datasets and fits
% CREATEFIT(ARG_1,ARG_2)
% 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: 2
% Number of fits: 0
%
% See also FITDIST.
% This function was automatically generated on 31-Jul-2019 10:21:33
% Data from dataset "Mode1":
% Y = arg_1 (originally DMLT20M1(:,5))
% Data from dataset "Mode2":
% Y = arg_2 (originally DMLT20M2(:,5))
% Force all inputs to be column vectors
arg_1 = arg_1(:);
arg_2 = arg_2(:);
% Prepare figure
clf;
hold on;
LegHandles = []; LegText = {};
% --- Plot data originally in dataset "Mode1"
[CdfF,CdfX] = ecdf(arg_1,'Function','cdf'); % compute empirical cdf
BinInfo.rule = 1;
[~,BinEdge] = internal.stats.histbins(arg_1,[],[],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} = 'Mode1';
% --- Plot data originally in dataset "Mode2"
[CdfF,CdfX] = ecdf(arg_2,'Function','cdf'); % compute empirical cdf
BinInfo.rule = 1;
[~,BinEdge] = internal.stats.histbins(arg_2,[],[],BinInfo,CdfF,CdfX);
[BinHeight,BinCenter] = ecdfhist(CdfF,CdfX,'edges',BinEdge);
hLine = bar(BinCenter,BinHeight,'hist');
set(hLine,'FaceColor','none','EdgeColor',[0.333333 0.666667 0],...
'LineStyle','-', 'LineWidth',1);
xlabel('Data');
ylabel('Density')
LegHandles(end+1) = hLine;
LegText{end+1} = 'Mode2';
% Create grid where function will be computed
XLim = get(gca,'XLim');
XLim = XLim + [-1 1] * 0.01 * diff(XLim);
XGrid = linspace(XLim(1),XLim(2),100);
% Adjust figure
box on;
hold off;
% Create legend from accumulated handles and labels
hLegend = legend(LegHandles,LegText,'Orientation', 'vertical', 'FontSize', 9, 'Location', 'northeast');
set(hLegend,'Interpreter','none');
其中的坐标标签、图例、标题、线条颜色设置都显而易见,按自己的需求改正后把它保存下来,下次调用直接调用函数即可。另外附上颜色对照表(0-1取值)
https://wenku.baidu.com/view/111e6c47773231126edb6f1aff00bed5b8f3734e.html
ksdensity函数绘制线型的pdf
[f,xi] = ksdensity(x)
计算样本向量x的概率密度估计,返回在xi点的概率密度f,此时我们使用plot(xi,f)就可以绘制出概率密度曲线。该函数,首先统计样本x在各个区间的概率(与hist有些相似),再自动选择xi,计算对应的xi点的概率密度
绘制示例
clear;
clc;
%读数据
filename='E:\data\Mode2.xlsx';
data= xlsread(filename);
%选取指定表格中指定的列数据
%index是第几列,varname是对应的变量名字
varname={'Tu','Td','Te','Dst','MDst'};
index=[5,8,11,12,13];
for i=1:length(index)
[f(i,:),x(i,:)] = ksdensity(data(:,index(i)));
%绘制概率密度函数在不同的图形界面上
figure (i);
plot(x(i,:),f(i,:));
title(['figure',num2str(i),': pdf of ',char(varname(i))]);
axis([0 max(x(i,:)) 0 max(f(i,:))]);
end
运行效果:一下子弹出五个图,分别对应五列数据的pdf。这里只展示其中一张图
网友评论