How to add two cell arrays of the same dimensions

23 vues (au cours des 30 derniers jours)
Naza Karim
Naza Karim le 16 Juil 2019
Commenté : Star Strider le 16 Juil 2019
I have two cell arrays A and B, each of size 1x5 cells. Each cell is a row vector with different size (A{1}=B{1}=1x4 vector, A{2}=B{2}=1x5 vector...) where each cell in A is the same size of the corresponding cell in B. How can I add A+B?

Réponse acceptée

Star Strider
Star Strider le 16 Juil 2019
Try this:
A = [{rand(1,4)} {rand(1,5)}];
B = [{rand(1,4)} {rand(1,5)}];
Out = cellfun(@plus, A, B, 'Uni',0)
  7 commentaires
Star Strider
Star Strider le 16 Juil 2019
As always, my pleasure.
You can always put that in a loop if you have several cells to add, or use the arrayfun function that does the same thing (although less efficiently).
Star Strider
Star Strider le 16 Juil 2019
Unless you already coded the game board (if so, you need to post the code), that is going to require some time to write. The design of that code is not immediately obvious to me.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by