fileName='ExtractedDataandGraphs.xlsx';
data=xlsread(fileName);
t=1.5; w=1.27; l=4.49;
A=w*t;
time=data(1:24,2);
u=0.449;
F=data(1:24,3);
sigma=F/A;
fig0=figure;
plot(time,F); xlabel('time (s)'); ylabel('Force (MPa)');
fig1=figure;
h11=subplot(3,1,1);
plot(time, sigma);
xlabel('time (s)'); ylabel('stress (MPa)');
title('Cartilage');
%removing ramp
[maxS, idxMax]=max(sigma);
t1=time(idxMax:end);
t1=t1-t1(1);
sigma1=sigma(idxMax:end);
fig2=figure;
h12=subplot(3,1,2);
plot(t1,sigma1); legend('sigma from data');
xlabel('time (s)'); ylabel('sigma (MPa)');
%variable creation
xdata=t1;
ydata=sigma1;
%fitting function
fun2fit=@(params, time) params(1)*exp(-params(2)*t1)+params(3);
%guess parameters
guess=[100,40,10];
funGuess=fun2fit(guess,time);
plot(time,funGuess);
I have tried everything and looked at so many other forums. I cannot figure out what is wrong with this and why ot wont complete the last plot function.

 채택된 답변

Geoff Hayes
Geoff Hayes 2016년 2월 29일
편집: Geoff Hayes 2016년 2월 29일

0 개 추천

K - the error is because of this line
fun2fit=@(params, time) params(1)*exp(-params(2)*t1)+params(3);
Note how the second input parameter is time but you don't use it in the function. Rather you use t1 which is a 13x1 array. So the output of
funGuess=fun2fit(guess,time);
is a 13x1 array which when trying to plot it against the 24x1 time array at
plot(time,funGuess);
will lead to the above error. Just change your anonymous function to use time instead of t1
fun2fit=@(params, time) params(1)*exp(-params(2)*time)+params(3);

댓글 수: 1

Image Analyst
Image Analyst 2016년 2월 29일
Or even better, call it something other than time since time() is a built-in function. I'd call it theTime or t instead.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

태그

아직 태그를 입력하지 않았습니다.

질문:

2016년 2월 29일

댓글:

2016년 2월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by