Please help me sir i am stuck in matlab with a program. Sir, I am using MATLAB 2015a while running a program as below for I get an error like this "Error: Function definitions are not permitted in this context."
1 次查看(过去 30 天)
显示 更早的评论
function dhdt = tankfill(t,h)
A = 10 + 4*sin(t);
H = 2*sqrt(h);
dhdt = A - H;
tspan = [0 30];
h0 = 1;
[t,h] = ode45(tankfill,tspan,h0);
plot(t,h)
Error: Function definitions are not permitted in this context.
0 个评论
回答(1 个)
Walter Roberson
2018-3-5
编辑:Walter Roberson
2018-3-5
You need to store the first four lines of that code in a file named tankfill.m, but the lines starting from the assignment to tspan should either go into a different file or should go on the command line.
In R2015a it was never valid to try to define a function at the command line, and it was never valid to try to define a function inside a script file (a script file is any .m file whose first executable line is not 'function' or 'classdef'). A later MATLAB release made it possible to define functions inside script files in some circumstances, but even in the very latest versions it is never valid to define a function at the command line.
4 个评论
Walter Roberson
2018-3-5
Create a new directory. Unzip the attached file into that directory. Inside MATLAB, cd to that directory. At the command line give the command
drive_a_tank
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!