I want to change the marker size and line width for my following plot:
function [fitresult, gof] = createFit(diameter, time)
%CREATEFIT(DIAMETER,TIME)
% Create a fit.
%
% Data for 'Raw Data' fit:
% X Input : diameter
% Y Output: time
%%Fit: 'Raw Data'.
[xData, yData] = prepareCurveData( diameter, time );
% Set up fittype and options.
ft = fittype( 'power1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [155.522818446907 -1.88432816467686];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'Raw Data' );
h = plot( fitresult,'b', xData, yData, '.k', 'MarkerSize',10); %Works without 'MarkerSize',10 but not with it
legend( h, 'time vs. diameter', 'Raw Data', 'Location', 'NorthEast' );
% Label axes
xlabel diameter
ylabel time
grid on
hold on;
axis([0 22 0 41]);

 채택된 답변

dpb
dpb 2018년 7월 9일
편집: dpb 2018년 7월 10일

0 개 추천

h = plot( fitresult,'b', xData, yData, '.k', 'MarkerSize',10);
Looks like you've exceeded the smarts of the enhanced plot command; granted it looks like it might should work but I don't see that the extra named parameters are actually listed in the doc.
I'm guessing you'll need to go at it in two steps; either separate the fit and the data plots initially or
hL=plot(fitresult,'b', xData, yData, '.k');
hL(1).'MarkerSize'=10;
I'm guessing will work....might be worth a support request unless somebody sees something I missed. Complexity has its paybacks in adding all these objects and so on--the interfaces just get more and more convoluted.
Addendum Test above; does work with the correction that it's hL(1) that's the data line, not hL(2) I had presumed first based on order in the argument list.
Worth a query to TMW on whether the original should work or not; I'm not positive altho I'm guessing they'll say "no"...

추가 답변 (1개)

Image Analyst
Image Analyst 2018년 7월 10일
편집: Image Analyst 2018년 7월 10일

0 개 추천

When you call
h = plot( fitresult,'b', xData, yData, '.k', 'MarkerSize',10);
why can't you just pass in a variable instead of 10? And pass in the 'LineWidth' property too.
markerSize = randi([5 25], 1,1); % Whatever you want...
lineWidth = 3; % Whatever...
h = plot(fitresult,'b', xData, yData, 'k.-', ...
'MarkerSize', markerSize, ...
'LineWidth', lineWidth);

댓글 수: 4

Same problem, plot can't parse the additional named parameters in the form of a (fitObject, lsFit, x, y, lsData), at least thru R2017b.
>> load census
>> f=fit(cdate,pop,'poly2');
>> ms=15;
>> hL=plot(f,'b',cdate,pop,'.k','markersize',ms);
Error using cfit/plot>parseinput (line 357)
Argument 7 is incorrect
Error in cfit/plot (line 42)
[S1,xdata,ydata,S2,outliers,S3,ptypes,conflev] = parseinput(alltypes,varargin);
>>
Doesn't matter what the parameter name is for all I tried; doesn't look like TMW implemented adding named parameters on the end for this particular syntax.
If one tries to remove the linestyle placeholder argument and use a named parameter pair, that string is interpreted as if it were intended to be an excluded-point vector in that position.
It's such a convoluted an interface trying to keep the original placed variables consistent with original ML design and adding the fit object into the mix besides with named parameters at least so far it just can't handle additional named pairs tacked on the end.
dpb
dpb 2018년 7월 10일
편집: dpb 2018년 7월 10일
OK, I looked at the input parser...at this point it expects one of the following argument types...
K>> alltypes
alltypes =
1×8 cell array
Columns 1 through 7
{'fit'} {'predfunc'} {'predobs'} {'residuals'} {'stresiduals'} {'deriv1'} {'deriv2'}
Column 8
{'integral'}
K>>
It's not looking for other optional named parameters at all so anything one puts in that position other than one of the other fit results will fail.
Image Analyst
Image Analyst 2018년 7월 10일
I guess I never have this problem because I don't plot multiple curves in one call to plot(). I just use multiple calls to plot() where each one plots one curve.
dpb
dpb 2018년 7월 10일
Yes, much cleaner syntax that way; this is all a fignewton created by the attempt to overload plot with all these extra features for other objects besides just x, y plots.
They've created a monster by going down this road from which now there probably is no return but also no way to go forward cleanly.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

질문:

2018년 7월 9일

댓글:

dpb
2018년 7월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by