'"Too many input arguments." errror remove
1 次查看(过去 30 天)
显示 更早的评论
1 %% Scoutbees: random search (only once)
2 U=X_random(n, para1_max, para2_max, para3_max, para4_max,para1_min,para2_min, para3_min, para4_min );
3 for S= 1: n
4 input = ([U(S,1),U(S,2),U(S,3),U(S,4)]);
5 Par_Q(S,1)= BLPMSM_1_75kW_640RPM(input);
6 end
7 Q= sortrows([ U(:,1), U(:,2),U(:,3), U(:,4),Par_Q],5);
8 clear U;
9
error show in line 5.. how to remove this eror
Error using fxbxuntitled>BLPMSM_1_75kW_640RPM
Too many input arguments.
Error in fxbxuntitled (line 5)
Par_Q(S,1)= BLPMSM_1_75kW_640RPM(input);
2 个评论
回答(1 个)
Walter Roberson
2021-4-22
function bf
Which is a function that does not accept any parameters.
Then you have some stuff, and then you have
function bf(output)
end
which declares a different function named bf that expects one parameter, and does no work.
Normally MATLAB would have given you an error about having two functions by the same name in the same file. However...
Par_Q(S,1)= BLPMSM_1_75kW_640RPM(input);
we can tell from that line that you stored those functions in a file named BLPMSM_1_75kW_640RPM.m and that inside BLPMSM_1_75kW_640RPM.m you do not have any function named BLPMSM_1_75kW_640RPM . When you have a file that starts with a function, then MATLAB treats the first function specially, and ignores the function name that you coded for it, and treats it as-if you had coded the name of the file as the function name. So MATLAB is treating the file as-if you had started it with
function BLPMSM_1_75kW_640RPM
and then there is no conflict about bf being duplicated because it is treating the first one as-if it were named BLPMSM_1_75kW_640RPM .
... But this still leaves you with the problem that your function is not expecting any parameter, and also leaving you with the unused function bf at the end of the file.
2 个评论
Walter Roberson
2021-4-22
You start the file with
function bf
which declares that bf is a function that accepts no input and creates no output.
Then you have
U=X_random(n, para1_max, para2_max, para3_max, para4_max,para1_min,para2_min, para3_min, para4_min );
input= [U(:,1),U(:,2),U(:,3),U(:,4)]
Par_Q(S,1)= bf(input);
That attempts to invoke bf with one parameter, and returning a scalar. But you declared that function bf does not accept any inputs and does not produce any outputs. You are within function bf but you are trying to call function bf... and failing because function bf does not accept any inputs.
You have nested function definition
function bf(output)
end
and perhaps you were thinking that the nested function would be called instead of the function you are already inside. But even if that worked, that second bf might accept an input parameter but it does not return any outputs, so you would fail the assignment to Par_Q(S,1) which requires that the function produces an output.
- Do not use one function name for two different purposes inside the same code: it is going to confuse yourself,and confuse other people reading the code, and possibly confuse MATLAB. Rename your functions so it becomes clear which function is being called at which point;
- The function you call there must accept one parameter of input (that is a vector of 4 values), and must return a scalar.
I suspect that at that point in the code, the function that is being invoked is intended to be the function you are optimizing over four parameters. You have not defined what you are optimizing anywhere.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!