Not Enough Input Arguments
이전 댓글 표시
I've only been using Matlab for around 2 months and Im trying to make a function that recognizes new inputs. I have "Num" defined in another function as a character array, everytime "Num" is changed I want to run it through this function. The issue is that when I attempt to test the function it recognizes the input has changed, but stops me at "Not Enough Input Arguments" Its a relatively simple function, and whenever I attempt to alter it I get "Unrecognized function or variable 'Num'." instead. I just want an Idea of how I should go abou this.
Here is the test function;
In this case I wanted to define x as 1 if strncmpi(Num(1), '1',1) was true, but I dont know where to proceed. I also wanted to add that when I try this function in command window alone it works just fine and udates x as a new variable.
% Out.m
function x = Out(Num)
if strncmpi(Num(1), '1',1)
x = 1;
disp(x)
end
댓글 수: 4
Num = '14534535';
x = Out(Num)
Num = '54534535';
x = Out(Num)
% Out.m
function x = Out(Num)
x = 0;
if strncmpi(Num(1), '1',1)
x = 1;
%disp(x)
end
end
Mason
2023년 11월 11일
Torsten
2023년 11월 11일
I don't see that you call the function somewhere with an input argument for "Num". What do you expect as output if you don't supply input ?
Walter Roberson
2023년 11월 11일
If you have a named parameter Num and you do not pass in a value in the corresponding position, and you have a variable named Num in your base workspace (such as a script)... then MATLAB will never look in the base workspace to see if you have Num defined there. never .
In every case when you have a named parameter to a function, and you do not pass a value in the corresponding position in the function call, then it is an error to try to use the value of that variable name (unless, that is, your code already assigned a value to the variable.)
This is a strict rule. Named parameters are never searched for outside of the function they are a named parameter of.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




