Suppose I have a sparse matrix F of order 4 x 4. Now I want to store this sparse matrix in 3d matrix. What is the syntax for this representation. that is I want to assign A(:, :,1) = F. Since F is sparse it is showing an error. But if I assign A(:, :,1) = full(F), then it is working. But in that case F is not sparse. F consists of many zeros. Kindly tell me how to assign a sparse matrix in a 3d matrix.

댓글 수: 3

KSSV
KSSV 2018년 7월 11일
You need to read about sparse matrix. sparse saves only non-zero values and their respective indices. If you want to assign it into a 3D matrix, obviously you need to use full matrix. You cannot simply assign sparse to a 3D matrix. If you still insist on, you can save sparse into a cell, so that it can save your memory.
Guillaume
Guillaume 2018년 7월 11일
@TR RAO, You've already asked this question a day earlier. No matter how many times you asked, the answer will be the same.
TR RAO
TR RAO 2018년 7월 11일
Sir, Thank You Sir. Yesterday I could not understand after reading sparse matrices. Now I understood.

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

답변 (1개)

Matt J
Matt J 2018년 7월 11일
편집: Matt J 2018년 7월 11일

4 개 추천

You can't hold a normal Matlab 3D array in sparse form, but you can do it with my ndSparse class (Download), as long as you're mindful of the limitations.
Afull=cat(3,eye(4),diag([14,0,0,27])); %example
Afull(2,3,2)=52;
F=sparse(diag([20,0,40,50])); %example
>> A=ndSparse(Afull); A(:,:,1)=F,
A(:,:,1) =
(1,1) 20
(3,3) 40
(4,4) 50
A(:,:,2) =
(1,1) 14
(2,3) 52
(4,4) 27
>> whos A Afull
Name Size Bytes Class Attributes
A 4x4x2 160 ndSparse
Afull 4x4x2 256 double

카테고리

도움말 센터File Exchange에서 Sparse Matrices에 대해 자세히 알아보기

질문:

2018년 7월 11일

댓글:

2018년 7월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by