필터 지우기
필터 지우기

Extract data using ginput and fit with a formula of your choice

조회 수: 6 (최근 30일)
C A
C A 2021년 6월 15일
댓글: JJ Lamb 2021년 6월 16일
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)*exp(-(x-x(1))/T)+y(2)
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?
  댓글 수: 3
C A
C A 2021년 6월 16일
Yes, I already have a plot. I just need to fit the curve between the two points that I choose, instead of fitting the entire data set.
Mathieu NOE
Mathieu NOE 2021년 6월 16일
hello
maybe if you share the code and data I can work on it

댓글을 달려면 로그인하십시오.

채택된 답변

JJ Lamb
JJ Lamb 2021년 6월 16일
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
figure
plot(xData,yData,'rx'); % original data
hold on
xx = min(xData):max(xData)-min(xData)/100:max(xData); % dummy variable for plotting
plot(xx,myFun(TT,xx),'b')
  댓글 수: 2
C A
C A 2021년 6월 16일
Thank you, may I ask why you have used 2 here (yData = myData(x(1):x(2),2)) instead of 1 ?
JJ Lamb
JJ Lamb 2021년 6월 16일
I assumed that the y data was in the second column. Column 1 is x data, column 2 is y data. You may have them in separate variables already, in that case you would just need:
xData = oldX(x(1):x(2));
yData = oldY(x(1):x(2));

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

태그

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by