fmincon in for loop

hello, I am trying to use fmincon inside a for loop such as described in the following code:
for i=1:size(X)
Xd=[X(i);Y(i)];
opts = optimoptions('fmincon','Algorithm','sqp');
f= fmincon(@(x)objfun(x,u,l,c),x0,[],[],[],[]...
,[],[],@(x)confcn(x,u,l,c,Xd),opts);
FF(i)=f;
end
When i fixe Xd, without using for loop, it run greatly. But with for loop, it generate this error:"Subscripted assignment dimension mismatch".
have you some idea to advise me?

1 件のコメント

Star Strider
Star Strider 2016 年 10 月 29 日
Yes!
If it runs correctly without the for loop, don’t use the for loop!

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

回答 (1 件)

Matt J
Matt J 2016 年 10 月 30 日
編集済み: Matt J 2016 年 10 月 30 日

0 投票

it generate this error:"Subscripted assignment dimension mismatch".
You should be giving us more information than this (a copy/paste of the whole error message). MATLAB error messages will tell you specifically which line of code and which command is generating the error.
However, I assume the problem is in this line
FF(i)=f;
If f is a vector, you cannot stick it in a scalar location FF(i). Use FF(i,:) or FF(:,i) or whatever is appropriate to the shape of 'f' and the shape of the FF that you have pre-allocated.

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2016 年 10 月 29 日

編集済み:

2016 年 10 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by