Hello, I am trying to include the following simple code as one of my constraints in my optimization model:
if Xij = 1, then Xik=0 for all k not equal j.
Please assist. Cheers

回答 (1 件)

dpb
dpb 2018 年 4 月 15 日
編集済み: dpb 2018 年 4 月 15 日

0 投票

One way; may be more better...presuming X is square...
is1=(X==1);
X(is1 & ~eye(size(X)))=0;
Oh!...easy enough if isn't square, too...
is1=(X==1);
X(is1 & ~eye(min(size(X))))=0;

カテゴリ

タグ

タグが未入力です。

質問済み:

2018 年 4 月 15 日

編集済み:

dpb
2018 年 4 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by