MATLAB Answers


Change width on fitted line in function fitlm

Vlatko Milic さんによって質問されました 2019 年 11 月 21 日 10:25
最新アクティビティ dpb
さんによって コメントされました 2019 年 11 月 22 日 13:16
さんの 回答が採用されました
I can't change the witdh on a fitted line based on X number of data points when I use fitlm-function. I am only able to change the width of the data points themselves.
Do you have any ideas?
The code is:
Kind regards, Vlatko

  0 件のコメント

サインイン to comment.


1 件の回答

回答者: dpb
2019 年 11 月 21 日 13:21

Yeah, save the handles returned by plot for the linear model fit...
You can find this out by returning the handle array from plot and see that it is a four-handle array...and example here was
>> load carsmall % MATLAB sample data set
>> lm=fitlm(MPG,Weight); % fit a simple model
>> figure
>> hLM=plot(lm) % plot it, return handles array
hLM =
4×1 Line array:
Line (Data)
Line (Fit)
Line (Confidence bounds)
>> hLM(2).LineWidth % the fit is the second handle in the arrray; query it
ans =
>> hLM(2).LineWidth=1; % set it to new value

  5 件のコメント

2019 年 11 月 21 日 16:35
TMW only set a value for 'DisplayName' on one of the two confidence bounds lines so wouldn't have duplicates in the legend box.
The two confidence lines are the last two in the array; you have to set both to change both. You can only set one handle at a time using dot notation; set() the function will let you do both in a single call.
Vlatko Milic 2019 年 11 月 22 日 9:41
Thank you! However, I don't really follow the last line:" set() the function will let you do both in a single call".
What should I set?
2019 年 11 月 22 日 13:16
'linewidth' property
set(hLM(3:4),'LineWidth',1); % set both confidence lines same time
See doc set for details...

サインイン to comment.

Translated by