フィルターのクリア

Summing matrices without loop

3 ビュー (過去 30 日間)
Esegboria Osarhemen
Esegboria Osarhemen 2019 年 3 月 3 日
I have a this function
function mat(i)
which generates an nxn matrix for a value of i. There are 10000 possible values of i, hence 10000 possible nxn matrices. I want to use mat(i) in another function and sum the 10000 possible matrices. How can i do this without a loop?

採用された回答

Walter Roberson
Walter Roberson 2019 年 3 月 3 日
all_mat = arrayfun(@mat, 1:10000, 'uniform', 0);
total = sum( cat(3,all_mat{:}), 3 );
This still uses a loop: it is just a hidden loop. It is probably less efficient than using a loop.
  1 件のコメント
Esegboria Osarhemen
Esegboria Osarhemen 2019 年 3 月 4 日
Thanks

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

その他の回答 (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