필터 지우기
필터 지우기

sort cell arrays based on mean value

조회 수: 6 (최근 30일)
Amir Hosein Shokouhy
Amir Hosein Shokouhy 2021년 7월 17일
답변: Star Strider 2021년 7월 17일
Hi,
I have a 1*8 cell variable. I wanna sort these cells based on their mean values.
The mean valuse are as below:
Thanks,
Amir

채택된 답변

Star Strider
Star Strider 2021년 7월 17일
Try something like this —
c = mat2cell(rand(150,1), [10 20 30 40 50], 1) % Create Cell ARray
c = 5×1 cell array
{10×1 double} {20×1 double} {30×1 double} {40×1 double} {50×1 double}
[cm,idx] = sort(cellfun(@mean, c)) % Calculate & Sort By Means
cm = 5×1
0.4288 0.4607 0.4721 0.5427 0.5889
idx = 5×1
5 3 4 1 2
c_sorted = c(idx) % Sorted Cell Array
c_sorted = 5×1 cell array
{50×1 double} {30×1 double} {40×1 double} {10×1 double} {20×1 double}
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by