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 ExchangeMATLAB についてさらに検索

製品

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by