Sortrows function and real-time systems
Mostrar comentarios más antiguos
I would like to understand if sortrows is suited for real-time systems.
Is it based on a recursive algorithm?
Respuesta aceptada
Más respuestas (1)
Ameer Hamza
el 20 de Mayo de 2020
Editada: Ameer Hamza
el 20 de Mayo de 2020
Although the documentation does not mention the complexity of the algorithm. However, since the lower-bound on sorting have the complexity of
, and the experimental results also seem to confirm that
n_rows = round(linspace(1000, 1000000, 50));
t = zeros(1, numel(n_rows));
for i=1:numel(n_rows)
M = rand(n_rows(i), 3);
t(i) = timeit(@() sortrows(M));
end
%%
x = n_rows;
y = t;
figure;
plot(x, y, '+');
xlabel('Num. Rows');
ylabel('Execution Time');

The dependance on number of columns also seems to be linear
n_rows = 10:10:500;
t = zeros(1, numel(n_rows));
for i=1:numel(n_rows)
M = rand(10000, n_rows(i));
t(i) = timeit(@() sortrows(M));
end
%%
x = n_rows;
y = t;
figure;
plot(x, y, '+');
xlabel('Num. Columns');
ylabel('Execution Time');

So now it depends on your application, whether this complexity is acceptable. However, its performance already seems to be optimal, and you cannot gain much speed by using some other algorithm.
Categorías
Más información sobre Startup and Shutdown 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!

