Why I am getting error message when I try to define line specs of a plot?

72 次查看(过去 30 天)
Hello
I am trying to fit a curve to a data and create a plot. The code creates the plot, but when I define the line width, it gives error message;
f = fittype('a + b*log(x)',...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'a','b'});
fit1 = fit( time1, strain1, f )
plot(fit1,'k-','LineWidth',2)
The error message I got is below;
fit1 =
General model:
fit1(x) = a + b*log(x)
Coefficients (with 95% confidence bounds):
a = 0.04434 (0.04336, 0.04532)
b = 0.004645 (0.004399, 0.004891)
Index exceeds matrix dimensions.
Error in cfit/plot (line 66)
ydata = ydata(idx);
It does not give any error message if I do not define 'LineWidth'.
Waiting for your kind help.
Regards

采纳的回答

Walter Roberson
Walter Roberson 2019-4-8
plot() for cfit objects is not the generalized plot function. It does not accept LineWidth parameters.
You should proceed like
h = plot(fit1, 'k-');
set(h, 'LineWidth', 2);

更多回答(2 个)

A. Sawas
A. Sawas 2019-4-8
This will solve the problem.
p = plot(fit1,'k-');
p.LineWidth = 2;

TADA
TADA 2019-4-8
You are using an overload of plot that accepts a cfit object
this overload doesn't support all the functionality of the regular plot function
you can calculate the fit data and plot that, or you can take a handle of the curve and fix that later:
time1 = (1:100)';
strain1 = log(time1);
f = fittype('a + b*log(x)',...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'a','b'});
fit1 = fit( time1, strain1, f );
% calculate the fit vector and plot numbers
y = feval(fit1, time1);
plot(time1, y, 'k-', 'LineWidth', 2);
% manipulate the curve handle after plotting
h = plot(fit1,'k-');
h.LineWidth = 2;

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by