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

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 日

0 投票

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 日
I do appreciate your help, the former code is this:
current_path = pwd;
DeltaSOC_all = [];
%%%%%Aquí se obtienen los "deltaSOC"
for i=1:100
FolderName=['CMkb1_', num2str(i)];
cd([pwd,'\',FolderName]);
load soc
soc_i=[soc.time([1]), soc.data([1])];
soc_fin=[soc.time([end]), soc.data([end])];
DeltaSOC=(soc_fin(2)-soc_i(2));
DeltaSOC_all=[DeltaSOC; DeltaSOC_all];
cd(current_path)
end
%%%Variable de entrada de irradiación
IrradiationTotal_Jm2=10440;
irr3 = ones(100, 1);
I_3=irr3*IrradiationTotal_Jm2;
Irradiationmin_Jm2=340;
irr1 = ones(100, 1);
I_1=irr1*Irradiationmin_Jm2;
Irradiationmode_Jm2=4660;
irr2 = ones(100, 1);
I_2=irr2*Irradiationmode_Jm2;
Irradiationmedia_Jm2=12009;
irr4 = ones(100, 1);
I_4=irr3*Irradiationmedia_Jm2;
IrradiationMAX_Jm2=31690;
irr5 = ones(100, 1);
I_5=irr5*IrradiationMAX_Jm2;
%%%Distribucion de Placas
PV_100=1105.*ones(10,1);
PV90=1105*0.9.*ones(10,1);
PV80=1105*0.8.*ones(10,1);
PV70=1105*0.7.*ones(10,1);
PV60=1105*0.6.*ones(10,1);
PV50=1105*0.5.*ones(10,1);
PV40=1105*0.4.*ones(10,1);
PV30=1105*0.3.*ones(10,1);
PV20=1105*0.2.*ones(10,1);
PV10=1105*0.1.*ones(10,1);
V2 =[PV_100; PV90; PV80; PV70; PV60; PV50; PV40; PV30; PV20; PV10];
%%%%Distribucion de las baterias
Bateries_100=186;
B9=Bateries_100*0.9;
B8=Bateries_100*0.8;
B7=Bateries_100*0.7;
B6=Bateries_100*0.6;
B5=Bateries_100*0.5;
B4=Bateries_100*0.4;
B3=Bateries_100*0.3;
B2=Bateries_100*0.2;
B1=Bateries_100*0.1;
u =[Bateries_100; B9; B8; B7; B6; B5; B4; B3; B2; B1];
V3=repmat(u,10,1); %%%%%para convertir el VECTOR V3 en un arreglo de 100 elementos para permutarlo con las otras 2 variables (irr y PV)
delta_soc1=flip(DeltaSOC_all);
% a=delta_soc
% % %%%%%%%Aqui ya estan las variables de entrada
V_in=[I_1,flip(DeltaSOC_all) I_2, flip(DeltaSOC_all), I_3, flip(DeltaSOC_all), I_4, flip(DeltaSOC_all), I_5, flip(DeltaSOC_all) V2, V3 ];
%
Jon
Jon 2020 年 2 月 14 日
Thank you for trying to include the code, but you don't show the critical part which is the call to the function Riesgo_C
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 日

0 投票

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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeArgument Definitions についてさらに検索

製品

リリース

R2018b

質問済み:

2020 年 2 月 14 日

編集済み:

2023 年 11 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by