Speed up comparing two arrays and write into new array
Mostrar comentarios más antiguos
Hello,
I compare values of two arrays, and write the values of an associated array into a new one. Unfortunately, this comparison is quite slow. I know vectorization is a way to do it, but I don't know how in this case. Below are smaller arrays for testing, it can go up to 1'000'000 x T or so. Looking at the profiler data, the comparison takes 99% of the time for below code snippet with large arrays.
I got three initial arrays:
coordIndex: 514x4 double (integer), with most values occurring several times. Same values as in Vert_ID_mat, so 218 different values. Array can contain NaN-Values
Vert_ID_mat: 218x1 double (integer), every value only once
Colors_Res: 514x4 cell (strings). Can contain zeros, which are associated to the NaN-values
Resulting array:
Assoc_Colors: 218x1 cell (strings)
I use following code right now:
for k = 1:size(coordIndex,1)
for kk = 1:size(coordIndex,2)
for i = 1:size(Vert_ID_mat,1)
if coordIndex(k,kk) == Vert_ID_mat(i) %isequal
Assoc_Colors{i} = Colors_Res(k, kk);
end
end
end
end
Assoc_Colors = Assoc_Colors.';
How can I write a faster code and achieve a faster processing time?
Best regards
Daniel
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Time Series Events en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!