Index in position 1 exceeds array bounds (must not exceed 1).

5 次查看(过去 30 天)
SunDNImeasm = [600; 700];
powerPrice = [100; 100];
Power = zeros(1,length(SunDNImeasm));
Revenue = zeros(1,length(SunDNImeasm));
M1v = zeros(1,length(SunDNImeasm));
M2v = zeros(1,length(SunDNImeasm));
massFlow = zeros(1,length(SunDNImeasm));
for i=1:length(SunDNImeasm)
Sun.DNI.Value = SunDNImeasm(i);
M1measm.Value = para(1,i);
M2measm.Value = para(2,i);
When I run the above with GA optimizer
ga(@EbsOptimize5_2,nvars,[],[],[],[],lb,ub,[],[],options);
with nvars = 2, I get the following error:
Index in position 1 exceeds array bounds (must not exceed 1).
M2measm.Value = para(2,i);
  11 个评论
Walter Roberson
Walter Roberson 2020-6-12
It works in my tests. For example,
function varargout = test_multi_out(para)
Power = (para-7).^3;
revenue = (para+9)/5;
massflow = 1-para;
fitness = (para+42).^2;
varargout{1} = fitness;
if nargout > 1
varargout{2} = Power;
varargout{3} = revenue;
varargout{4} = massflow;
end
end
tested with
bestpara = ga(@test_multi_out,1);
[best_cost, Power, revenue, massflow] = test_multi_out(bestpara)

请先登录,再进行评论。

回答(1 个)

madhan ravi
madhan ravi 2020-6-12
Para is a row vector according to your error message.
  4 个评论
Hussain Ja
Hussain Ja 2020-6-12
编辑:Hussain Ja 2020-6-12
Since the program doesn't run, I can't get any output. So unable to check what
size(Para)
gives. Is there another way of checking its size?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by