フィルターのクリア

Sum of multiple cell in for loop

1 回表示 (過去 30 日間)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016 年 4 月 2 日
If i have a n number of cell and i want to calculate each cell independent for example
A{1}= 1
3
5
2
Then the solution will be 11
Then
A{2} = 3
2
5
7
Then the solution will be 17
Then
A{3} = 2
3
7
8
Then the solution will be 20
  • how can i do this for A{k}???

採用された回答

Chad Greene
Chad Greene 2016 年 4 月 2 日
編集済み: Chad Greene 2016 年 4 月 2 日
You can do this in a loop like:
% Preallocate a variable A_sum:
A_sum = NaN(size(A));
% Loop through each cell:
for k = 1:length(As)
A_sum(k) = sum(A{k});
end
But cellfun is shorter and faster:
A_sum_better = cellfun(@sum,A)
  1 件のコメント
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016 年 4 月 2 日
Thank you

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by