Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create a very large matrix using matlab

Tags:

matlab

I have a problem with matlab when I'm trying to create a a matrix with a very large size such as 40000x40000.

for example:

x=zeros(40000,40000);

the error message is "??? Maximum variable size allowed by the program is exceeded. "

is there any solution.

Also I have another question, can we have a matrix with variable column size such as in java.

like image 340
osama alia Avatar asked Feb 02 '10 11:02

osama alia


1 Answers

40000 * 40000 * 8 bytes per number = 12 GB, surely you won't have enough memory.

To create a huge matrix with lots of zeros, you need a sparse matrix:

m = sparse(40000, 40000)

To create an array of variants, you can use a cell array:

m = cell(3, 1)
m(1) = [1,2,3]
m(2) = [2,4,6,8,10]
m(3) = 6+6i
like image 178
kennytm Avatar answered Oct 02 '22 12:10

kennytm