Azzera filtri
Azzera filtri

Take specific elements from each cell of a cell array

2 visualizzazioni (ultimi 30 giorni)
Hello! Let A be a 1x10 cell array. Each of the 10 cells of A are nxm matrices.
Also, let an 1x10 vector x, that is, x=[ x1 x2 ... x10 ].
I would like to take the x1 row from the first cell of A, the x2 row from the second cell of A, and so on for all the 10 cells of A.
I have tried cellfun, but I did not achive my goal.
Thanks in advance.

Risposta accettata

Walter Roberson
Walter Roberson il 2 Ott 2020
cellfun(@(a, X) a(X,:), A, x, 'uniform', 0)
  3 Commenti
Vasilis Chasiotis
Vasilis Chasiotis il 2 Ott 2020
I fixed it!
cellfun(@(a, X) a(X,:), A, num2cell(x), 'uniform', 0)
Walter Roberson
Walter Roberson il 2 Ott 2020
Yes, sorry, that is a good solution there.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by