フィルターのクリア

sum values in a cell array

240 ビュー (過去 30 日間)
elisa ewin
elisa ewin 2016 年 4 月 29 日
回答済み: BINGXIN YAN 2021 年 7 月 12 日
Hello! I have
a={0.006;0.45;0.1;0.23;0.12}
and I want to sum all the values in a, how can i do?

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 29 日
編集済み: Azzi Abdelmalek 2016 年 4 月 29 日
sum([a{:}])
or you can use cell2mat
b=cell2mat(a)
out=sum(b)

その他の回答 (1 件)

BINGXIN YAN
BINGXIN YAN 2021 年 7 月 12 日
What if the cell is more complicated?
I have a{1,1}=[1,1];a{1,2}=[0,1];a{1,3}=[2,5],
and I want to sum all the values in a{1,:}(1), for example
a{1,1}(1)+a{1,2}(1)+a{1,3}(1)=1+0+2, how can I do except restoring a{1,:}(1) in another matrix or array.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by