How to define variable sets for changing value of i ?

1 view (last 30 days)
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 Comments
Star Strider
Star Strider on 28 Jan 2018
Please describe what you want to do and what your variables are (and their row and column dimensions).
MANISH KUMAR
MANISH KUMAR on 28 Jan 2018
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.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 28 Jan 2018
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.

Community Treasure Hunt

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

Start Hunting!