フィルターのクリア

How to add the corresponding values in different matrices

3 ビュー (過去 30 日間)
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2017 年 11 月 7 日
コメント済み: MAHMOUD ALZIOUD 2017 年 11 月 8 日
Dear All, I have 4 matrices, the first one dimension is a= 0 by 0, the 2nd one is b= 44661 by 1, the 3rd one is c = 10 by 1 and the 4th one is d= 35533 by 1. they are vectors with different number of rows but one column each. I need to create a new vector e that equals ( a+b+c+d) in which i sum the corresponding cells but it keeps giving me this message: Matrix dimensions must agree. I know why but I need to solve it please. How can I do that?

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 11 月 7 日
編集済み: Andrei Bobrov 2017 年 11 月 8 日
C = {a,b,c,d};
c1 = cellfun(@(x)[(1:numel(x))',x(:)],C,'un',0);
c1 = cat(1,c1{:});
out = accumarray(c1(:,1),c1(:,2));
  3 件のコメント
Andrei Bobrov
Andrei Bobrov 2017 年 11 月 8 日
fixed.
MAHMOUD ALZIOUD
MAHMOUD ALZIOUD 2017 年 11 月 8 日
thank you very much Sir for your help.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by