How to take a number inside cell array

1 visualización (últimos 30 días)
Ahmad Bayhaqi
Ahmad Bayhaqi el 5 de Jul. de 2021
Comentada: Stephen23 el 6 de Jul. de 2021
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.

Respuesta aceptada

Stephen23
Stephen23 el 5 de Jul. de 2021
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 comentarios
Ahmad Bayhaqi
Ahmad Bayhaqi el 6 de Jul. de 2021
Editada: Ahmad Bayhaqi el 6 de Jul. de 2021
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 el 6 de Jul. de 2021
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Types en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by