Not Enough Input Arguments
Mostra commenti meno recenti
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 Commenti
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
il 11 Nov 2023
Torsten
il 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
il 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.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Simulink Environment Customization in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




