How do I use the new curve fit function to fit me curve?

4 visualizzazioni (ultimi 30 giorni)
Hi, I am seriously struggling with this as im not a coder and do not dare aspire to be one but none the less I am trying to create a function from the variables ro3 and temp so I can then use that function to manipulate other variables I am yet to create. I was following the curve fitting for non-coders but I have gotten lost after creating a function to match my curve...
%Very Basic graph plot...
clc; %Clear
temp=[-15,-10,-5,0,10,20]; %Defining Temp points -15deg C to 20deg C
ro3=[3300,790,300,138,99,72]; %defining Resistivity Ohm.m(sqrd)
%I previously used CurveFit function to define my function 'TempFit'
%General model:
% cf(temp) = a*exp(-b*temp)+c
% Coefficients (with 95% confidence bounds):
% a = 0.1419
% b = 0.4218
% c = -1.887e-15 (-26.78, 26.78
cf=NewTempFit(ro3,temp); %load my Curve fit function
temperature=logspace(-1,2,100);
r3=cf(temperature); %Plot temp - ro3 as points only
plot(temperature,r3)
grid %display grid
title('Graph of Soil Resistivity with Temp and moisture content of %15 soil weight') %Name of Graph
ylabel('Typical Resistivity (Ohm.m)') %Y axis label
xlabel('Temperture (Deg C)') %x axis label
here is my curve fit function
function [fitresult, gof] = createFit(temp, ro3)
%CREATEFIT(TEMP,RO3)
% Create a fit.
%
% Data for 'Ohm.m-Temp' fit:
% X Input : temp
% Y Output: ro3
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 09-Sep-2018 09:51:12
%%Fit: 'Ohm.m-Temp'.
[xData, yData] = prepareCurveData( temp, ro3 );
% Set up fittype and options.
ft = fittype( 'a*exp(-b*temp)+c', 'independent', 'temp', 'dependent', 'ro3' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.141886338627215 0.421761282626275 0.915735525189067];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'Ohm.m-Temp' );
h = plot( fitresult, xData, yData );
legend( h, 'ro3 vs. temp', 'Ohm.m-Temp', 'Location', 'NorthEast' );
% Label axes
xlabel temp
ylabel ro3
grid on
For whatever reason I cannot get this functions to impose itself on the values when i plot them. Any assistance would be much appreciated.
  1 Commento
Astha Singh
Astha Singh il 17 Set 2018
Hi Matthew,
I understand that you have already written the function 'NewTempFit' and now facing an error while using the same to get a plot.
To understand where you are facing the error, can you please define the 'NewTempFit' function that you are using in your code?

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by