フィルターのクリア

How to take a number inside cell array

4 ビュー (過去 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 Center および File ExchangeData Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by