How to locate the index of cell array that has highest element value?

조회 수: 2 (최근 30일)
Abdulaziz Abutunis
Abdulaziz Abutunis 2021년 8월 4일
댓글: Abdulaziz Abutunis 2021년 8월 8일
Hi All
I have a main cell array (matrix) that contains several cell arrays. Is it possible to locate the index of cell array that has highest third element. In other word want to know whcih cell array has the highest value locaed in third element.
Best regards
Aziz

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 8월 4일
편집: Sulaymon Eshkabilov 2021년 8월 4일
You can do it with sort() and by manipulating your main cell array a little bit. See this plain example:
A{1,1}=1; A{2,1}=5; A{3,1}=2; A{4,1}=13; A{5,1}=7; A{6,1}=1i; A{7,1}=0;
B={A}
[Bsorted, idx] = sort(cell2mat(B{:}), 'descend')
IDX_max=idx(1) % Max value's INDEX
B_max = B{1}(IDX_max)
You may also consider this matlab script published in MATLAB central: https://www.mathworks.com/matlabcentral/fileexchange/13770-sorting-a-cell-array
  댓글 수: 1
Abdulaziz Abutunis
Abdulaziz Abutunis 2021년 8월 8일
Thank you Sulaymon,
I was able to handle it with regular matrx. Though you suggestion seems valid
Regards
Aziz

댓글을 달려면 로그인하십시오.

카테고리

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