Change width on fitted line in function fitlm

Hi,
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:
mdl=fitlm(T(Index,3),F);
plot(mdl)
title(strcat(subfoldernames))
Kind regards, Vlatko

 Respuesta aceptada

dpb
dpb el 21 de Nov. de 2019
Yeah, save the handles returned by plot for the linear model fit...
mdl=fitlm(T(Index,3),F);
hMDL=plot(mdl);
hFIT=findobj(hMDL,'DisplayName','Fit');
hFIT.LineWidth=1;
...
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)
Line
>> hLM(2).LineWidth % the fit is the second handle in the arrray; query it
ans =
0.50
>> hLM(2).LineWidth=1; % set it to new value
>>

5 comentarios

Vlatko Milic
Vlatko Milic el 21 de Nov. de 2019
Thank you, I hope one day I become good as you in Matlab :)
It worked like a charm!
Vlatko Milic
Vlatko Milic el 21 de Nov. de 2019
Editada: Vlatko Milic el 21 de Nov. de 2019
Dpd,
When I use Confidence bounds only the lower line-widht is changed and not the upper? What can I do?
Regards, Vlatko
dpb
dpb el 21 de Nov. de 2019
Editada: dpb el 21 de Nov. de 2019
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
Vlatko Milic el 22 de Nov. de 2019
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?
'linewidth' property
set(hLM(3:4),'LineWidth',1); % set both confidence lines same time
See doc set for details...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 21 de Nov. de 2019

Comentada:

dpb
el 22 de Nov. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by