how to do the addition of the cell matrix ?

1 回表示 (過去 30 日間)
Akash Pal
Akash Pal 2022 年 6 月 28 日
コメント済み: Dyuman Joshi 2022 年 6 月 28 日
val(:,:,1) =
0 67.5000 0 67.5000 0
0 67.5000 0 67.5000 0
val(:,:,2) =
79.3333 0 0 39.6667 0
59.5000 0 59.5000 0 0
I am writting this manually then only this two cell value is adding and showing me the summation but if my cell is more than 2 that time how to do it autimatically ,Which will show me the result of the call value together after addition ?This all cell are under one cell .
totalresult2=(totalresult(:,:,1))+(totalresult(:,:,2))
totalresult2 =
79.3333 67.5000 0 107.1667 0
59.5000 67.5000 59.5000 67.5000 0
I want the result like this .

採用された回答

Stephen23
Stephen23 2022 年 6 月 28 日
編集済み: Stephen23 2022 年 6 月 28 日
The simple and efficient MATLAB approach is to use SUM():
val = cat(3,[0,67.5000,0,67.5000,0;0,67.5000,0,67.5000,0],[79.3333,0,0,39.6667,0;59.5000,0,59.5000,0,0])
val =
val(:,:,1) = 0 67.5000 0 67.5000 0 0 67.5000 0 67.5000 0 val(:,:,2) = 79.3333 0 0 39.6667 0 59.5000 0 59.5000 0 0
mat = sum(val,3)
mat = 2×5
79.3333 67.5000 0 107.1667 0 59.5000 67.5000 59.5000 67.5000 0
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2022 年 6 月 28 日
sum() should be the right answer for numeric arrays, but I am confused by OP's use of term - cell arrays.

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by