フィルターのクリア

function which will read in a data set by executing a script

1 回表示 (過去 30 日間)
LINDO MTSWENI
LINDO MTSWENI 2019 年 4 月 24 日
編集済み: Rik 2019 年 4 月 24 日
A function is required which will read in a data set by executing a script called PlotData. This will create two variables in the workspace called IndependentData and DependentData. A plot must be presented to the user of the data in these variables in which DependentData is plotted as discrete data points against IndependentData. The user must then be asked to enter an order for the polynomial that they believe will best fit the data set. The program must fit the polynomial specified by the user and update the plot with a smooth line representing the polynomial values over the same data range as IndependentData. The user must then be asked if they wish to change their selected order and update the plot accordingly. This process must be repeated until the user is satisfied with their fit. The user must then be asked to provide annotation for the graph axes and a legend should be added indicating Original Data and Fitted Polynomial for the two data sets respectively. The final polynomial must also then be displayed to the user in an easily readable format assuming that the symbol for IndependentData is x and that for DependentData is y.
BELOW IIS THE CODE I HAVE CREATED SO FAR,
% this is the data in PlotData
%IndependentData = -20:1:20;
%DependentData = [ 39218.0748349476 31904.825803731 32000.4338380778 21935.683886364 19990.0979315708 18687.6603905942 13047.8208695011 11521.4235811694 12069.8048715325 8745.08042059282 8984.24761104227 3639.02928026784 5412.74603756423 9026.21997344237 1379.79509525278 1437.41399331365 3654.2051597246 1919.10088245875 6236.72058927372 2763.08853637826 1506.12716694362 4958.58568049569 1773.67472929593 4442.61066727712 5779.32964332972 4848.20104613495 3233.93834291259 2577.44151971506 3408.79568796045 -2200.11323144139 2234.17832386795 -1253.44864193157 -1245.52731402615 -2986.45114443796 -8968.49172029456 -7299.67616217405 -8309.4291092513 -16512.2595056024 -22277.6870671567 -24256.6697817702 -27649.2691258117];
%This function plots a graph and the line of best fit to the users wish
function Tutorial9(IndependentData, DependentData)
run PlotData; %Loads the *.m file
plot(IndependentData, DependentData, 'k .') %This is the initial plot without the line of best fit
C=0;
while strcmpi(C,'yes') ==0 %The while loop ensures the user is happy with the line of best fit
A = inputdlg ('Enter an order for the polynomial that you believe will best fit the data set') %Asks the user for the order of the line of best fit
A = str2num(cell2mat(A));
B = polyfit(IndependentData,DependentData,A); %Creates the coeffcients for the line of best fit
X2 = linspace(min(IndependentData), max(IndependentData), 1000); %X-values for the line of best fit
Y2 = polyval(B,X2); %Y-Value for the line of best fit
plot(IndependentData,DependentData,'k .', X2, Y2, 'k') % Plots the initial graph and the line of best fit
C = questdlg('Are you happy with the order?') %Asks the user if they are happy with the graph
end
end
this is the part im failoing to do.
The user must then be asked if they wish to change their selected order and update the plot accordingly. This process must be repeated until the user is satisfied with their fit. The user must then be asked to provide annotation for the graph axes and a legend should be added indicating Original Data and Fitted Polynomial for the two data sets respectively. The final polynomial must also then be displayed to the user in an easily readable format assuming that the symbol for IndependentData is x and that for DependentData is y.
please help and thank you in advance
  1 件のコメント
Rik
Rik 2019 年 4 月 24 日
Note that this is a Matlab forum. As long as your question also applies to Matlab that is generally not a problem, but please avoid Octave-specific syntax.
As for your actual question I'm a bit confused. You seem to have everything working. What is your problem? It looks like the only missing part is the annotation and readable output. The first works similiarly to what you have, and the second depends on what you think is readable.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by