필터 지우기
필터 지우기

How to solve this error "Not enough input arguments."

조회 수: 154 (최근 30일)
Tony Castillo
Tony Castillo 2020년 2월 14일
편집: Walter Roberson 2023년 11월 21일
Dear all,
I have this code, though, I have previously defined all the variables, it still persist a message:
Not enough input arguments.
Error in Riesgo_C (line 2)
aux1 = V_in(V_in(:,12) == BATT,:);
The function:
function [deltaSOC] = Riesgo_C(V_in,BATT,PV,IRR)
aux1 = V_in(V_in(:,12) == BATT,:);
aux2 = aux1(aux1(:,11) == PV,:);
auxD = aux2(:,[2;4;6;8;10]);
auxI = aux2(:,[1;3;5;7;9]);
p = polyfit(auxI(1,:),auxD(1,:),1);
deltaSOC = polyval(p,IRR);
end
  댓글 수: 2
Adam
Adam 2020년 2월 14일
Functions have to be called with arguments actually passed in as they have their own sealed workspace, unlike a script. They know nothing at all about what exists in the calling workspace so you have to call the function as
[deltaSOC] = Riesgo_C(V_in,BATT,PV,IRR);
when you call it in order for it to have the inputs it needs.
Tony Castillo
Tony Castillo 2020년 2월 17일
Thanks Adam

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

채택된 답변

Jon
Jon 2020년 2월 14일
Your function requires 4 input arguments. You must have called it with less than 4 input arguments. Please check your code where you call the Riesgo function to make sure that you in fact have 4 input arguments. If you can not find the mistake, then please copy the exact code where you call the function and post it here.
  댓글 수: 4
Tony Castillo
Tony Castillo 2020년 2월 14일
Because I have not made a call to my function yet, I just was testing it with the variables loaded in the workspace, might it be the problem ?
Jon
Jon 2020년 2월 14일
So then please copy and paste the command you are issuing to call it from the command line that produces the error. I think that you probably forgot to include one of the input parameters. You need to have 4.

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

추가 답변 (1개)

madhu
madhu 2023년 11월 21일
Not enough input arguments.
Error in mylaplasian (line 6)
[rows, cols]=size(g);
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 11월 21일
편집: Walter Roberson 2023년 11월 21일
You are running a function named mylaplasian which accepts one or more inputs, one of which is named g in the function. But when you run mylaplasian then you are not passing in enough parameters to put anything into the g slot.
You should rewrite your function to do something appropriate when the user calls it with fewer parameters than the maximum. For example,
mytest(10,20)
Input P was: 10 Input Q was: 20
mytest(30)
Input P was: 30 Input Q was: -99
mytest()
Error using solution>mytest
You need to pass at least one parameter to this function!
function mytest(P,Q)
if nargin < 2; Q = -99; end
if nargin < 1
error('You need to pass at least one parameter to this function!');
end
fprintf('Input P was: %g\n', P);
fprintf('Input Q was: %g\n', Q);
end
This code illustrates that you can detect that trailing optional parameters have not been passed in, and in that case you can put in default values if appropriate -- but that when the user has not passed in enough parameters for minimal functionality, that you should generate a meaningful error message to inform the user of what is needed.

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

카테고리

Help CenterFile Exchange에서 Automotive에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by