フィルターのクリア

adding cells of two arrays

5 ビュー (過去 30 日間)
Sumanth
Sumanth 2023 年 3 月 1 日
コメント済み: Stephen23 2023 年 3 月 1 日
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 件のコメント
Sumanth
Sumanth 2023 年 3 月 1 日
Thank you!!

サインインしてコメントする。

回答 (2 件)

Star Strider
Star Strider 2023 年 3 月 1 日
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 件のコメント
Stephen23
Stephen23 2023 年 3 月 1 日
cellfun(@plus, A,B, 'Unif',0)

サインインしてコメントする。


Sumera Zem
Sumera Zem 2023 年 3 月 1 日
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

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by