Sortrows function and real-time systems
Mostra commenti meno recenti
I would like to understand if sortrows is suited for real-time systems.
Is it based on a recursive algorithm?
Risposta accettata
Più risposte (1)
Ameer Hamza
il 20 Mag 2020
Modificato: Ameer Hamza
il 20 Mag 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.
Categorie
Scopri di più su Startup and Shutdown in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

