Register to reply

Matlab: Data from Best Fit Lines into Legend

by SeannyBoi71
Tags: data, legend, lines, matlab
Share this thread:
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
'Office life' of bacteria may be their weak spot
Lunar explorers will walk at higher speeds than thought
Philips introduces BlueTouch, PulseRelief control for pain relief
Mar13-12, 02:15 PM
Sci Advisor
PF Gold
Integral's Avatar
P: 7,337
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.
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.

Mar13-12, 03:19 PM
Sci Advisor
PF Gold
f95toli's Avatar
P: 2,262
Matlab: Data from Best Fit Lines into Legend

Just use the num2str command on the values that polyfit returns
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