matlab - 如何将误差线添加到 MatLab 的 cftool 生成的曲线拟合散点图?
问题描述
我正在尝试使用 MatLab 的 cftool 创建一个图形,并将垂直误差线添加到 y 数据中。我一直在尝试更改创建图形的自动生成代码。
我曾尝试使用 errorbar 函数,但是当我这样做时,它会覆盖给定的图。即,它创建了一个线图(点不应连接,)并且曲线拟合也不存在。我检查了绘图功能的文档,但似乎没有向数据添加误差线的选项。
function [fitresult, gof] = TungstenFit(Bin,Count,CountError)
[xData, yData] = prepareCurveData( Bin, Count );
% Set up fittype and options.
ft = fittype( 'b+m*x+A1*exp(-(x-u1)^2/(2*s1^2))+A2*exp(-(x-u2)^2/(2*s2^2))+A3*exp(-(x-u3)^2/(2*s3^2))', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [0 0 0 0 -Inf -Inf -Inf -Inf 100 150 150];
opts.StartPoint = [850 500 50 0 -10 10 10 10 140 160 185];
opts.Upper = [Inf Inf Inf 10 Inf Inf Inf Inf Inf Inf Inf];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'W3LsFit' );
h = plot( fitresult, xData, yData );
legend( h, 'Tungsten Bin Counts', 'W3LsFit', 'Location', 'NorthWest' );
% Label axes
xlabel Bin
ylabel Tungsten Bin Count
grid on
此代码创建一个散点图,其中包含数据并绘制曲线拟合函数。但是,它目前对 CountError 数据没有任何作用。
我对 MatLab 很陌生(我必须自学这个任务,)所以任何帮助或提示将不胜感激。谢谢。
解决方案
我有一个可行的解决方案。对于后代,这是我在创建绘图和图例函数之间添加的代码:
hold on
e = errorbar(xData,yData,CountError,'LineStyle','none');
第一行导致绘图不被覆盖,'LineStyle','none' 参数导致 errorbar 函数添加误差线而不在数据点之间绘制一条线。
推荐阅读
- javascript - Angular 6 setTimeout Module not found: Error: Can't resolve 'timers'
- javascript - Python相当于选择第一个非空参数
- go - 使用 gorilla mux 提供静态 html 文件
- python - Pandas Dataframe - 更改数据结构(重新组织)
- sql-server - EF 2.1 中的播种日期
- google-apps-script - 在 Google 表格插件中,如何检查用户是否已购买订阅?
- c++ - 如何区分使用运算符调用的常量和非常量方法
- java - 从 javax.enterprise.context 而非 javax.faces.bean 导入 sessionbean
- html - 无法让 ngMouseEnter(和类似命令)正常工作
- java - 如何确定Android中两个视图的共同超级视图