how to do linear line in GUI

i want to insert linear line like the first picture and if possible the equation of y intercept too.
second picture is the command for the GUI window and the last pic is the current graph

3 comentarios

Walter Roberson
Walter Roberson el 27 de Dic. de 2020
sy w
sy w el 3 de En. de 2021
hi, thank you for sparing your time answering this question. but this solution also doesn't work. do you perhaps have any other command that might help?
Walter Roberson
Walter Roberson el 4 de En. de 2021
You can record the handle of the refline() and set the LineStyle property to '--' to get the broken line.

Iniciar sesión para comentar.

Respuestas (1)

Cris LaPierre
Cris LaPierre el 4 de En. de 2021
Editada: Cris LaPierre el 4 de En. de 2021

1 voto

You would do it the same way you would in MATLAB.
If you have the curve fitting toolbox, use the function fit with the fitType set to 'poly1'.
If you don't, use polyfit to perform linear regression. See this example.
Incidentally, either approach will return you the slope (m) and intercept (b), which you can use with refline. If you want the fit line to extend beyond the data, create an X vector that covers the range of values you would like, and use your equation to compute the corresponding Y values.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 27 de Dic. de 2020

Editada:

el 4 de En. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by