![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/277258/image.png)
unknown code- understand it up to the for loop but am lost from there. Can anyone lend a hand? thanks.
2 次查看(过去 30 天)
显示 更早的评论
dat=load('data.dat')
a=dat(:,1)
b=dat(:,2)
s=size(a)
s=s(1)
out=zeros(s,1)
for n=1:s
out(n)=(b(n+1)-b(n-1))/(a(n+1)-a(n-1))
end
c=[a out]
0 个评论
采纳的回答
Thiago Henrique Gomes Lobato
2020-3-15
What the code was supposed to be? it looks like the variable out is suppose to be the numerical derivative of b with respect to a. If the distance between each "a" is uniform and increasing, than this is the central scheme for 1st order differentiation with 2nd order accuracy and the line describe basically
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/277258/image.png)
2 个评论
Thiago Henrique Gomes Lobato
2020-3-15
Size returns two values, so s(1) saves the first dimension in order to perform the loop and size assignment. It would be the same if you did:
s=size(a,1);
out=zeros(s,1);
...
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!