Not Enough Input Arguments
Ältere Kommentare anzeigen
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 Kommentare
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
am 11 Nov. 2023
Torsten
am 11 Nov. 2023
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
am 11 Nov. 2023
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.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Simulink Environment Customization finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




