필터 지우기
필터 지우기

How to define variable sets for changing value of i ?

조회 수: 1 (최근 30일)
MANISH KUMAR
MANISH KUMAR 2018년 1월 28일
답변: Star Strider 2018년 1월 28일
for Example, in below code, I defined 'DSet' and 'DCount' initially. I want to define these sets for each value of i.
for i=1:nPop
DSet=[];
DCount=0;
end
F{1}=[];
for i=1:nPop
for j=i+1:nPop
p=ResultM(:,:,i);
p1=Obj1(i);
p2=Obj2(i);
q=ResultM(:,:,j);
q1=Obj1(j);
q2=Obj2(j);
if Dominates(p1,q1,p2,q2)
DSet=[DSet j];
DCount=DCount+1;
end
end
end
I want to define the sets 'DSet' and 'DCount' for each i. I tried 'DSet(i)' and 'DCount(i)', but this doesn't work. Please help me in getting the right solution for this. Thanks in anticipation.
  댓글 수: 2
Star Strider
Star Strider 2018년 1월 28일
Please describe what you want to do and what your variables are (and their row and column dimensions).
MANISH KUMAR
MANISH KUMAR 2018년 1월 28일
Sir, I want to define empty sets ([]); DSet and DCount for each individual value of i. For example, if i =1:5, then I need 5 different sets of DSet and DCount, so that as the loop runs from i=1 to i=5 and if statement is true, these sets can be updated and fetched separately for each i.

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2018년 1월 28일
I still do not understand what you want to do. However, if you want to preallocate them, that is easy.
Delete these lines because you do not need the loop:
for i=1:nPop
DSet=[];
DCount=0;
end
and replace them with:
DSet = zeros(1,nPop);
DCount = 0;
and assuming that I understand what you want to do, the if block then becomes:
if Dominates(p1,q1,p2,q2)
DCount=DCount+1;
DSet(DCount) = j;
end
Experiment to get the result you want.

카테고리

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