필터 지우기
필터 지우기

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'.

답변 (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.
.

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 CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by