Borrar filtros
Borrar filtros

No dublicates in for loop.

2 visualizaciones (últimos 30 días)
Kian Kirchhof
Kian Kirchhof el 29 de Dic. de 2016
Comentada: Kian Kirchhof el 29 de Dic. de 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) ;
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.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by