How to take a number inside cell array
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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)
3 个评论
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
D = D(X)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!