No dublicates in for loop.
2 ビュー (過去 30 日間)
古いコメントを表示
Im doing a project on directed networks. I have a 2000x2 array in total created by a loop, running 9 times (once per week.) I need for every week to have no dublicated rows, but dublicated rows are allowed in the array for all weeks. I dont doubt the answer is simple, but i cant come up with new answers right now.
the loop is like this
for k=1:9
for i=1:length(NumeriskData)
if NumeriskData(i,DateRow)>= Ar(k,1) && NumeriskData(i,DateRow)<= Ar(k,2)
if NumeriskData(i,RowSorter)== 1 || NumeriskData(i,RowSorter2)== 1 || NumeriskData(i,RowSorter3)== 1
if NumeriskData(i,1)~= NumeriskData(i,2)
WeightLink(Count+1,:)= NumeriskData(i,1:2) ;
Count=Count+1;
end
end
end
end
end
Unique(WeightLink) after here would just take uniques of the total array, i need it to take of every k run, and still make the proper total WeightLink
EDIT. Sorry, not sure how to format the code properly.
0 件のコメント
採用された回答
David J. Mack
2016 年 12 月 29 日
編集済み: David J. Mack
2016 年 12 月 29 日
Hey Kian,
I am not sure if I really understood your problem, but maybe the following solution helps:
%Assuming NumeriskData is a nx2 matrix.
for k=1:9
IsData = NumeriskData(:,DateRow)>= Ar(k,1) ...
& NumeriskData(:,DateRow)<= Ar(k,2) ...
& NumeriskData(:,1)~= NumeriskData(:,2) ...
& (NumeriskData(:,RowSorter )== 1 ...
| NumeriskData(:,RowSorter2)== 1 ...
| NumeriskData(:,RowSorter3)== 1);
if any(IsData)
NumDatWeek = unique(NumeriskData(IsData,:),'rows');
nNumDataWeek = size(NumDatWeek,1);
WeightLink(Count+1:Count+nNumDataWeek,:) = NumDatWeek;
Count = Count+nNumDataWeek;
end
end
Greetings, David
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!