Sort elements in cell array in descending order

조회 수: 6 (최근 30일)
Panos Kerezoudis
Panos Kerezoudis 2023년 5월 11일
댓글: Panos Kerezoudis 2023년 5월 11일
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