No dublicates in for loop.

2 ビュー (過去 30 日間)
Kian Kirchhof
Kian Kirchhof 2016 年 12 月 29 日
コメント済み: Kian Kirchhof 2016 年 12 月 29 日
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.

採用された回答

David J. Mack
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
  1 件のコメント
Kian Kirchhof
Kian Kirchhof 2016 年 12 月 29 日
Never done if statements like that. You actually did what i needed, only had to change very small amount. Sweet, thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by