method is the name of the function and also a variable stored in the script. Matlab cant call the function because it sees it as the variable
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
24 次查看(过去 30 天)
显示 更早的评论
Got the above error when trying to assign some variables from another function. the error occurs on line: [uInitial,xInitial,tInitial]=method(dtmin,xmax,dxmin,method,L);
and the method function, called, is defined:
function [u, x, t] = method(dt, xmax, dx, method,L)
0 个评论
采纳的回答
Timothy Dunning
2023-4-19
2 个评论
Walter Roberson
2023-4-19
Yes, that can cause that problem.
These days, however, more typically MATLAB would notice if you tried to switch between using a name as a function and using a name as a variable, and would complain (in an unclear way.)
However, in the case where you assign to a name before the first place in the code that the name is intended to be used as a function call, and the defining function is not in the same file, then MATLAB is unable to tell that you intended a function call
更多回答(2 个)
Walter Roberson
2023-4-18
移动:Walter Roberson
2023-4-18
The function method that you think you are calling in the statement
[uInitial,xInitial,tInitial]=method(dtmin,xmax,dxmin,method,L);
is not the same one that is defined with
function [u, x, t] = method(dt, xmax, dx, method,L)
For example, you might have a different function named method in your MATLAB path.
Or you might had a previous version of method that did not return as many as three outputs and you modified method since then to add more outputs, but MATLAB has not noticed that you modified method yet and is continuing to use the previous version of it.
The cases where MATLAB might not notice that you modified a file include:
- you modified a file using an external editor rather than the built-in editors. The built-in editors notify MATLAB when a file is modified but external editors do not.
- you might be using a function handle to a file and have modified the file; in such a case the function handle will not always notice and might continue to use the previous version.
- you might have stored method inside one of MATLAB's built-in directories. MATLAB never re-checks its built-in directories for changes, not unless it is specifically told to re-check them
For the first two cases, the trick is to clear the file name, such as clear method after modifying the file. The third case, where you stored the file inside MATLAB's installation directory... Don't Do That! rehash
2 个评论
Walter Roberson
2023-4-18
Or.... possibly the problem is happening somewhere inside method and you did not show us the complete error message and the appropriate code.
另请参阅
类别
在 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!