Sortrows function and real-time systems
Show older comments
I would like to understand if sortrows is suited for real-time systems.
Is it based on a recursive algorithm?
Accepted Answer
More Answers (1)
Ameer Hamza
on 20 May 2020
Edited: Ameer Hamza
on 20 May 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.
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
