Effacer les filtres
Effacer les filtres

adding cells of two arrays

5 vues (au cours des 30 derniers jours)
Sumanth
Sumanth le 1 Mar 2023
Commenté : Stephen23 le 1 Mar 2023
A = [10,9,13,21,18] [9,9,11,18,18]
B = [11,10,12,20,19] [10,9,13,21,18]
How can i add both?
such that C = [21, 19, 25, 41, 37] .....
Operator '+' is not supported for operands of type
'cell'.
  1 commentaire
Sumanth
Sumanth le 1 Mar 2023
Thank you!!

Connectez-vous pour commenter.

Réponses (2)

Star Strider
Star Strider le 1 Mar 2023
Perhaps something like this —
A = {[10,9,13,21,18] [9,9,11,18,18]};
B = {[11,10,12,20,19] [10,9,13,21,18]};
C = cellfun(@(x,y)x+y, A,B, 'Unif',0)
C = 1×2 cell array
{[21 19 25 41 37]} {[19 18 24 39 36]}
This assumes that ‘A’ and ‘B’ are cell arrays, as depicted here.
.
  1 commentaire
Stephen23
Stephen23 le 1 Mar 2023
cellfun(@plus, A,B, 'Unif',0)

Connectez-vous pour commenter.


Sumera Zem
Sumera Zem le 1 Mar 2023
A = {[10,9,13,21,18],[9,9,11,18,18]};
B = {[11,10,12,20,19],[10,9,13,21,18]};
C = cell(size(A)); % initialize C with the same size as A
for i = 1:numel(A)
C{i} = A{i} + B{i}; % add the corresponding arrays in A and B
end

Catégories

En savoir plus sur Data Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by