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에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!