How to define variable sets for changing value of i ?
1 次查看(过去 30 天)
显示 更早的评论
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
2018-1-28
Please describe what you want to do and what your variables are (and their row and column dimensions).
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!