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

16 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Walter Roberson
Walter Roberson le 8 Avr 2019
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);

Plus de réponses (2)

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

TADA
TADA le 8 Avr 2019
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;

Catégories

En savoir plus sur Fit Postprocessing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by