%% main2.m % This is a Matlab Script % Execute it by typing its name in the Matlab Command Window %% Define Test Data myx = (1:.1:10)'; % Manually enter data %mydata = [-28; 0; 10; 8; 0]; % Generate data using a model function mydata = model1(myx); % Generate normally distributed noise noise = 3*randn(size(mydata)); % Add noise to the sample data mydata = mydata + noise; %% Analyze Data % Polynomial fit p = polyfit(myx, mydata, 3) %% Plot the Sample Data plot(myx, mydata, 'Marker', '.', 'LineStyle','none'); xlabel({'Time'}); ylabel({'Measurement'}); title({'Sample Data'}); %% Plot the fit hold on values = polyval(p, myx); plot(myx, values, 'color', 'r'); hold off