No dublicates in for loop.

1 次查看(过去 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.

采纳的回答

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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by