Sum over cell array of sparse matrices error: Dimension for sparse matrix concatenation must be <= 2.

1 次查看(过去 30 天)
Hi all,
I have a cell contains sparse matrices,
K>> a
a =
2×1 cell array
[12×12 double]
[12×12 double]
Now I'd like to sum these 2 sparse matrices into 1. I tried:
K>> sum(cat(3, a{:}), 3)
which gave me error:
Error using cat
Dimension for sparse matrix concatenation must be <= 2.
This line works for non-sparse matrices, but not for sparse matrices. Any idea how to do it?
Thanks!

回答(1 个)

Andrei Bobrov
Andrei Bobrov 2017-11-3
a = cellfun(@full,a,'un',0);
sum(cat(3,a{:}),3);

类别

Help CenterFile Exchange 中查找有关 Sparse Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by