Could anyone help me with an error in my code?

조회 수: 2 (최근 30일)
Thobias Pereira Silva Thobias
Thobias Pereira Silva Thobias 2024년 1월 29일
댓글: Walter Roberson 2024년 1월 29일
function [y1] = ADDE(t,y)
y1 = zeros(size(y));
format long
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%----------------------------------
% Digester configurations and tspan
global q
global V_liq % Volume of liquid part
global V_gas % Volume of gas space
%Command windon:
%Not enough input arguments.
%Error in ADDE (line 2)
%y1 = zeros(size(y))
  댓글 수: 1
the cyclist
the cyclist 2024년 1월 29일
편집: the cyclist 2024년 1월 29일
What command are you using to call ADDE?
What is the output of the following commands?
which zeros -all
which size

댓글을 달려면 로그인하십시오.

답변 (2개)

the cyclist
the cyclist 2024년 1월 29일
Answering the questions in my comment above will clarify things, but I expect you are calling ADDE with either no arguments or one argument. For example
ADDE(1,2)
ans = 0
works, but
ADDE(1)
Not enough input arguments.

Error in solution>ADDE (line 4)
y1 = zeros(size(y));
gives the error you see.
function [y1] = ADDE(t,y)
y1 = zeros(size(y));
end
  댓글 수: 2
the cyclist
the cyclist 2024년 1월 29일
That is also the error you would get if you tried to call this function using the "Run" button in the edit window (and it will also pop up a window explaining why).
Walter Roberson
Walter Roberson 2024년 1월 29일
When you press the green Run button to run your code, then MATLAB does not go looking in the base workspace for definitions of the input parameters.
When you have named input parameters to a function, then inside the function itself, MATLAB will never search for values for the parameters. There are some circumstances under which MATLAB will search for variables, but those circumstances never apply to named parameters of the function.

댓글을 달려면 로그인하십시오.


Christopher McCausland
Christopher McCausland 2024년 1월 29일
Hi Thobias,
"Not enough input arguments" typically is thrown when the function is called without the required input variables; i.e.
[y1] = ADDE()
rather than;
t = 1:100;
y = 100;
[y1] = ADDE(t,y) % The important thing here is that t and y are defined and then included in your function call

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by