Borrar filtros
Borrar filtros

Logic indexing optimization of computational time

2 visualizaciones (últimos 30 días)
Rafael Félix Soriano
Rafael Félix Soriano el 29 de Ag. de 2023
Comentada: Torsten el 29 de Ag. de 2023
I am running a computationally expensive code, and according to MATLAB's profiler, this is the line of code that is taking the most time to run:
b = a(idx,:);
where a is 30000x3 matrix, and idx is a logical 30000x1 array, computed as follows:
idx = a(:,3) >= M + N;
where M and N are integers.
That line of code is run inside a for loop with many other lines with functions such as find. I need to understand why that line of code is taking longer to run than all other lines, and how I could optimize it. Sorry for the low amount of information on the code, for property reasons I cannot divulge much more.
Thank you in advance!
  5 comentarios
Rafael Félix Soriano
Rafael Félix Soriano el 29 de Ag. de 2023
Thank you for your answer Dyuman. My point is that having several lines of code running find, none of them are taking long. It is the one that I posted (b = a(idx,:)) that is taking significantly longer than all others. That is the only part of the code giving me problems.
I am sorry but I am not allowed to divulge any more info.
Torsten
Torsten el 29 de Ag. de 2023
Often, it is the interaction of many factors that makes a code slow. So concentrating on a single command is not the correct approach in my opinion.
That having said, b = a(idx,:) is the optimal way to extract the rows of the matrix "a" where the element of the 3rd column is >= M+N. Nothing to optimize or critisize here.

Iniciar sesión para comentar.

Respuestas (0)

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by