Register to reply 
Matlab: Data from Best Fit Lines into Legend 
Share this thread: 
#1
Mar1312, 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. 


#2
Mar1312, 02:15 PM

Mentor
P: 7,318

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.



#3
Mar1312, 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.



#4
Mar1312, 03:19 PM

Sci Advisor
PF Gold
P: 2,245

Matlab: Data from Best Fit Lines into Legend
Just use the num2str command on the values that polyfit returns



#5
Mar1312, 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 