필터 지우기
필터 지우기

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

조회 수: 5 (최근 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에서 Fit Postprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by