I am trying to use a script to run simpsons rule to numerically integrate a function, it keeps giving me an error.

조회 수: 1 (최근 30일)

답변 (2개)

Walter Roberson
Walter Roberson 2017년 7월 6일
You are trying to pass parameters to a script. You cannot do that. In order to be able to pass parameters to something, it has to be a function (or a class constructor.)
A script is a .m file whose first executable token is not either "function" or "classdef". You cannot pass parameters to them.
You need to add a "function" header line to your code.

James Tursa
James Tursa 2017년 7월 6일
편집: James Tursa 2017년 7월 6일
A script is an m-file that has MATLAB statements in it only, without a function statement. E.g.,
File myfun1.m:
x = 2*a;
File myfun2.m:
function x = myfun2(a)
x = 2*a;
return
end
The first file, myfun1.m, is a script file. It simply executes MATLAB statements based on the variables in your workspace. The second file, myfun2.m, is a function file. It takes an input argument and returns an output.
Your simpsonsrule.m file is apparently a script file like myfun1.m, but you are trying to call it like a function that takes inputs and returns outputs. To do that, you need to add in the function statement and set the return variables.

카테고리

Help CenterFile Exchange에서 Structured Data and XML Documents에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by