필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

intlinprog matrix creation help needed

조회 수: 1 (최근 30일)
Taner Cokyasar
Taner Cokyasar 2016년 7월 11일
마감: Stephen23 2016년 7월 11일
Hello,
I have the following sample vector named Zvalues:
Variable Name(Zim) Zvalues
Z11 0
Z12 0
Z13 1
Z21 0
Z22 1
Z23 0
Z31 0
Z32 1
Z33 0
I have created a zero 3x9 sized matrix as following:
Y= zeros(3, 9);
I want to fill this matrix with an if condition, as the following example:
if Zim=1, Yim=1
Y13 = 1 because Z13 = 1
Y22 = 1 because Z22 = 1
Y32 = 1 because Z32 = 1
The following matrix is what I want to reach at the end. 'Y's represent variable names, they are not a part of the matrix .
Y11 Y12 Y13 Y21 Y22 Y23 Y31 Y32 Y33
0 0 1 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 0
In other words, I want to formulate an Aeq matrix for coefficients of Y(im) variables given in the following equality constraint (to use with intlinprog):
Y(im)=t(m)-Z(im)*f(i) %construct this constraint for variables if Z(im)=1 (Zim is same as Zvalues)
%There is nothing to do with the RHS of the equality. It is just given to make the question more clear.
As seen in the equation, coefficients of all Y(im) variables are 1. In my sample I have 9 Y(im) variables, since i=3 and m=3. I will have larger dimensions. So, I need a MATLAB formulation for this mathematical form.
Thanks for help.
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 7월 11일
Taner Cokyasar
Taner Cokyasar 2016년 7월 11일
편집: Taner Cokyasar 2016년 7월 11일
I misstated everything in that question. So, I felt like opening a new topic could be better. If you may help me, I would really appreciate it.

채택된 답변

Taner Cokyasar
Taner Cokyasar 2016년 7월 11일
Answer by Stephen Cobeldick 28 minutes ago Edited by Stephen Cobeldick 27 minutes ago Accepted answer
Just use sub2ind:
>> Z = [0;0;1;0;1;0;0;1;0] Z = 0 0 1 0 1 0 0 1 0 >> Y = zeros(3,9); >> Y(sub2ind(size(Y),1:nnz(Z),find(Z).')) = 1 Y = 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0

추가 답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by