No dublicates in for loop.

1 Ansicht (letzte 30 Tage)
Kian Kirchhof
Kian Kirchhof am 29 Dez. 2016
Kommentiert: Kian Kirchhof am 29 Dez. 2016
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) ;
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.

Akzeptierte Antwort

David J. Mack
David J. Mack am 29 Dez. 2016
Bearbeitet: David J. Mack am 29 Dez. 2016
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;
Greetings, David
  1 Kommentar
Kian Kirchhof
Kian Kirchhof am 29 Dez. 2016
Never done if statements like that. You actually did what i needed, only had to change very small amount. Sweet, thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by