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
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!