Question
Hi, I want to plot a line passing through a set of points, which is as in the code below. To determine the slope I used polyfit. But it gives two outputs. I wonder which output I should consider out of the two outputs it is giving me? clc; clear; phi_1 = [0.1724*pi 0.1472*pi 2.18*pi 2.25*pi 4*pi 3.588*pi 1.012*pi 4.112*pi 4.31*pi 4.25*pi 0.832*pi]; x1 = linspace(0,1,11); figure(1) plot(x1,phi_1,'o'); coefficients1=polyfit(x1,phi_1,1) slope1=coefficients1(1); coefficients1=polyfit(x1,phi_1,1) coefficients1 = 1×2 7.6641 3.8373 slope1=coefficients1(1);
Expert Answer
Neeta Dsouza
PhD Expert
Answered Sep 12, 2026
The first line of the function description on the documentation for polyfit states precisely what those outputs are.
They are the coefficients of the descending powers of the fitted polynomial. You asked for a 1st-order polynomial, so the first element of the output is the coefficient of the linear (1st-order) term, and the second element of the output is the coefficient of the intercept (the 0th-order term).
clc; clear; phi_1 = [0.1724*pi 0.1472*pi 2.18*pi 2.25*pi 4*pi 3.588*pi 1.012*pi 4.112*pi 4.31*pi 4.25*pi 0.832*pi]; x1 = linspace(0,1,11); coefficients1=polyfit(x1,phi_1,1)
coefficients1 = 1×2
7.6641 3.8373
slope1=coefficients1(1); intercept1=coefficients1(2)
intercept1 = 3.8373

100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related slope Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →