필터 지우기
필터 지우기

How to take a number inside cell array

조회 수: 1 (최근 30일)
Ahmad Bayhaqi
Ahmad Bayhaqi 2021년 7월 5일
댓글: Stephen23 2021년 7월 6일
Hi,
For example I have a 3x2 cell matrix like this.
A {[32,28,30,31] [27,29,30] [32,29,31,27,28]}
B{[30,64,72,85] [15,33,62] [45,62,77,84,90]};
where every element has different size.
I want to take number in every element at B which corresponds to the max value of A in each element.
The expected results are to be like this C=[30],[62],[45]
How do I do this ? Thank you.

채택된 답변

Stephen23
Stephen23 2021년 7월 5일
A = {[32,28,30,31],[27,29,30],[32,29,31,27,28]};
B = {[30,64,72,85],[15,33,62],[45,62,77,84,90]};
F = @(a,b)b(max(a)==a);
C = cellfun(F,A,B)
C = 1×3
30 62 45
  댓글 수: 3
Ahmad Bayhaqi
Ahmad Bayhaqi 2021년 7월 6일
편집: Ahmad Bayhaqi 2021년 7월 6일
Just one more question, please.
What if the condition is with the nested cell array like this
A = {[27,28,30,31]},{[26,25,30]},{[33,29,31,27,28]};
B = {[30,64,72,85]},{[15,33,62]},{[45,62,77,84,90]};
How can I take a max value of all entry nested in A and pick a value in B which corresponds to the max value of A.
so the result will be:
C = 33
D = 45
Thank you
Stephen23
Stephen23 2021년 7월 6일
A = {[27,28,30,31],[26,25,30],[33,29,31,27,28]};
B = {[30,64,72,85],[15,33,62],[45,62,77,84,90]};
C = [A{:}];
D = [B{:}];
[C,X] = max(C);
C
C = 33
D = D(X)
D = 45

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by