Sort elements in cell array in descending order

6 次查看(过去 30 天)
Hi!
I hava a cell containing three row vectors and I would like to sort each vector in descending order.
Other than using a loop, is there a way to do this with the cellfun function? bc it automatically does it in ascending order.
This is the code that I used using cellfun.
thank you!
new_cell_array = cellfun(@sort, cell_array, 'UniformOutput', false);

采纳的回答

Stephen23
Stephen23 2023-5-11
fun = @(v) sort(v,'descend');
new_cell_array = cellfun(fun, cell_array, 'UniformOutput', false);
  1 个评论
Panos Kerezoudis
Panos Kerezoudis 2023-5-11
perfect thank you!
so for my learning, @(v) enables me to use/specify an existing function prior to inputting into cellfun?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by