%%%%%In this file, it will extract values of from the original file
which
%%%%%is acs107_coursework2. From these values it will then input new
%%%%%fields into the output. It will also find the best straight line
and
%%%%%the best quadratic from the selected value of x and y (selected
from
%%%%%choice_of_4) and plot it in figure 1.
function task1 = coa04kik_cw2_task1(input)
%%%Extract the variables
task_1=input{1};
set_of_data=task_1(1).choice_of_4;
task1=task_1(set_of_data);
figure(1);clf reset;
for numb=1:4;
xvalues=task1(numb).xvalues;
yvalues=task1(numb).yvalues;
%%%%insert the additional fields
task1(numb).linecoef=polyfit(xvalues,yvalues,1);
task1(numb).quadcoef=polyfit(xvalues,yvalues,2);
task1(numb).yline=polyval(task1(numb).linecoef,xvalues);
task1(numb).yquad=polyval(task1(numb).quadcoef,xvalues);
%%%%Plotting the graphs.
subplot(2,2,numb);
plot(xvalues,yvalues,'b',xvalues,task1(numb).yline,'y',xvalues,task1(numb).yquad,'r');
legend('Original graph','Best line','Best quadratic');
function_name=task1(numb).functionname;
title(function_name);
xlabel('value of x');
ylabel('value of y');
end
Friday, April 15, 2005
matlab hampeh
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment