Matlab: Data from Best Fit Lines into Legend

  • MATLAB
  • Thread starter SeannyBoi71
  • Start date
  • #1
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.

10aYi.jpg


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.
 

Answers and Replies

  • #2
Integral
Staff Emeritus
Science Advisor
Gold Member
7,201
56
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
I was aware of this method being the easy way out :tongue: 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
f95toli
Science Advisor
Gold Member
3,027
522
Just use the num2str command on the values that polyfit returns
 
  • #5
Ok this is what I was looking for, thank you.
 

Related Threads on Matlab: Data from Best Fit Lines into Legend

Replies
14
Views
1K
  • Last Post
Replies
6
Views
11K
Replies
1
Views
2K
Replies
4
Views
3K
Replies
5
Views
3K
Replies
0
Views
596
Replies
5
Views
1K
Replies
2
Views
7K
  • Last Post
Replies
1
Views
6K
Top