Matlab: Data from Best Fit Lines into Legend


by SeannyBoi71
Tags: data, legend, lines, matlab
SeannyBoi71
SeannyBoi71 is offline
#1
Mar13-12, 01:40 PM
P: 86
Hey all, I am plotting some data using matlab and have a question.

Basically, this is what I'm trying to do. I am calling a bunch of data from Excel, plotting this data in MATLAB (it gives me two lines), and then calculating the polyfit values for each line so I can find the equation y = mx +b for each one. I have no problem Doing all of this, but what I want to do next is display the polyfit data in the legend of the graph. I'm confused if this is possible with the legend function.



So in other words where it says 'Best Fit of Reflection 1' and 'Best Fit of Reflection 2' I want to somehow place the data calculated by polyfit in the form y = mx +b. Any suggestions? Thanks in advance.
Phys.Org News Partner Science news on Phys.org
Cougars' diverse diet helped them survive the Pleistocene mass extinction
Cyber risks can cause disruption on scale of 2008 crisis, study says
Mantis shrimp stronger than airplanes
Integral
Integral is offline
#2
Mar13-12, 02:15 PM
Mentor
Integral's Avatar
P: 7,292
This is simple in Excel, where you say you started. Chart the data, then pulldown the chart menu, select "add trendline" under options you can select to show the equations.
SeannyBoi71
SeannyBoi71 is offline
#3
Mar13-12, 02:28 PM
P: 86
I was aware of this method being the easy way out I am pretty proficient with Excel and have only recently started using Matlab, so I was trying to familiarize myself a little bit more with graphing this way.

f95toli
f95toli is offline
#4
Mar13-12, 03:19 PM
Sci Advisor
PF Gold
f95toli's Avatar
P: 2,198

Matlab: Data from Best Fit Lines into Legend


Just use the num2str command on the values that polyfit returns
SeannyBoi71
SeannyBoi71 is offline
#5
Mar13-12, 03:38 PM
P: 86
Ok this is what I was looking for, thank you.


Register to reply

Related Discussions
Dynamic Legend in MatLab Math & Science Software 3
Matlab Legend Problem Math & Science Software 0
Drawing field lines with MATLAB Engineering, Comp Sci, & Technology Homework 1
Draw Lines between Points in MATLAB Math & Science Software 13
Question about matlab figure legend. Math & Science Software 2