필터 지우기
필터 지우기

How to use matrix operations to find values of m and b in y=mx+b given two datasets to plot?

조회 수: 3 (최근 30일)
Hello,
Say I have array A = [ 0 1 2 3 4 ] and array B = [ 10 20 30 40 50]. If I am trying to plot the linear equation y=mx+b (A is the independent variable x and b is the dependent variable y), but do not know the values of m or b, how would I use matrix operations (like left hand division \) to find those values, and how would I then plot those values in a plot?

답변 (1개)

Image Analyst
Image Analyst 2017년 11월 26일
Not sure what x and y are, but if you're trying to fit B = mA+b, you can use polyfit:
% B = m * A + b;
A = [ 0 1 2 3 4 ]
B = [ 10 20 30 40 50]
coefficients = polyfit(A, B, 1)
m = coefficients(1)
b = coefficients(2)
  댓글 수: 1
Nickolas Vrvilo
Nickolas Vrvilo 2017년 11월 26일
X and y are the arrays A and B. I forgot to mention in my code that A is the independent variable x and B is the dependent variable y. Thank you!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by