Extract data using ginput and fit with a formula of your choice
9 views (last 30 days)
I am choosing two end points using ginput [x,y] = ginput(2) and then I need to separate my data set which lies between the two end points. The separated data set must be fitted into the following formula.
y(1),x(1),y(2) are the values taken from ginput. T is a parameter that I need to determine.
How can be done?
JJ Lamb on 16 Jun 2021
I'm going to say that the input data for the graph is in a 2 column vector called "myData"
[x,y] = ginput(2);
% assuming you need points based on where you clicked on the x axis
xData = myData(x(1):x(2),1);
yData = myData(x(1):x(2),2);
myFun = @(T,x) y(1)*exp(-(x-x(1))/T)+y(2); % copied your function
TT = lsqcurvefit(myFun,1,xData,yData); % TT is the result of the curvefit
% the second input 1 is just an initial guess.
% might need to adjust it to a more reasonable starting point for your data
% Plot your results
plot(xData,yData,'rx'); % original data
xx = min(xData):max(xData)-min(xData)/100:max(xData); % dummy variable for plotting