user192936
user192936

Reputation:

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, e.g. 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?

Upvotes: 0

Views: 282

Answers (1)

gevang
gevang

Reputation: 5014

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     

Upvotes: 1

Related Questions