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

조회 수: 3 (최근 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);
  댓글 수: 1
Xiaohan Du
Xiaohan Du 2017년 11월 3일
Nah, here a is 12 by 12 only for testing, in my real code it could be very large, so can only deal with sparse matrices, no back to full matrices.

댓글을 달려면 로그인하십시오.

카테고리

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