using this excel sheet, i have to do this homework for MATLAB and need help 1. W
ID: 3683361 • Letter: U
Question
using this excel sheet,
i have to do this homework for MATLAB and need help
1. Write a program that imports the data from the first excel sheet and plot each data set on the same plot. Create another program that plots all the data on its own graph but in the same window. Remember to include titles, legends, and axes labels.
2. Write a program that will read the data from the second tab. Use polyfit to create a linear best fit line. Calculate the R2 value for fit. Plot both the individual data points (red) and the fit line (blue) on the same graph. Include a title and axis labels.
i have to do this homework for MATLAB and need help
1. Write a program that imports the data from the first excel sheet and plot each data set on the same plot. Create another program that plots all the data on its own graph but in the same window. Remember to include titles, legends, and axes labels.
2. Write a program that will read the data from the second tab. Use polyfit to create a linear best fit line. Calculate the R2 value for fit. Plot both the individual data points (red) and the fit line (blue) on the same graph. Include a title and axis labels.
Explanation / Answer
Use MATLAB programs as shown below to achive your task:
(1.)
[v,T,vT]=xlsread('name.xls')
% 'xlsx' for exell 2007
%v: Double
%T and vT : cell
%use v containing numbers
t=v(:,1);y=v(:,2)
%if u have to plot second colone depending on first:
plot(t,y)
x1= [1 2];
y1 = [4 4];
ntimes = 100;
denom = 1;
k = -1;
subplot(1,2,1)
hp1 = plot(x1,y1);
xlabel('Updated with REFRESHDATA')
ylabel('pi')
set(gca,'Xlim',[0 ntimes],...
'Ylim',[2.5 4])
set(hp1,'XDataSource', 'x1')
set(hp1,'YDataSource', 'y1')
for t = 3:ntimes
denom = denom + 2;
x1(t) = t;
y1(t) = 4*(y1(t-1)/4 + k/denom);
refreshdata
drawnow
k = -k;
end
line([0 ntimes], [pi pi],'color','c')
(2)
x = 1:10;
y1 = x + randn(1,10);
scatter(x,y1,25,'b','*')
P = polyfit(x,y1,1);
yfit = P(1)*x+P(2);
hold on;
plot(x,yfit,'r-.');
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.