Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matlab question 2. Create a function called \"linear\" that takes a file name as

ID: 3734847 • Letter: M

Question

Matlab question

2. Create a function called "linear" that takes a file name as input, reads the file data (which has two columns of data) and creates two vectors ("x" and "y"), creates a plot, and outputs statistical information about the vectors. (25 points) The function should: Accept as input a file name Read the file and create two vectors of equal size (x and y) Create a scatter plot of x vs. y Place a linear regression line on the same plot. Print the mean and standard deviation of each data set. . .

Explanation / Answer

function linear(file)
data=load(file);
x=data(:,1);
y=data(:,2);
scatter(x,y);
p=polyfit(x,y,1);
hold on
plot(x,polyval(p,x))
fprintf('Mean of x: %.4f Standard Deviation of x: %.4f ',mean(x),std(x))
fprintf('Mean of y: %.4f Standard Deviation of y: %.4f ',mean(y),std(y))