简体   繁体   中英

Variable number of sparse matrices

I am trying to create variable number of sparse matrices. At first the best solution seemed to be creating a cell array and iteratively adding matrices to it however, eg the following code;

arr = {};
for i = 1:10
   arr = [arr sparse([],[],[],1000,1000)];
end

gives:

Error using ==> horzcat Attempt to convert to unimplemented sparse type

error. Do you have any suggestions?

Minor modification to your loop. Since you create the cell, assign a matrix in a cell element in each iteration:

arr = cell(1,10);
for i = 1:10
   arr{i} = sparse([], [], [], 1000, 1000);
end     

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM