From: Matt J on
arun <aragorn168b(a)gmail.com> wrote in message <a2418c7c-4b23-468b-bb10-d915cab5bb6e(a)s31g2000yqs.googlegroups.com>...
> Hi,
>
> Does anyone know about the principle behind *reshape* command of
> matlab, is it sophisticated or just using simple for-loops?


What John and Jan say is true of full matrices, but reshaping of sparse matrices is a little bit more sophisticated, because a sparse matrix object includes a table of the number of non-zero elements in each sparse matrix column. This means that reshaping a sparse matrix in a way that greatly increases the number of columns will greatly increase the amount of data in this table, accordingly. This can lead to potential memory overflow problems, as the following example shows:

>> [c,m]=computer;

>>S=sprand((m-3)/2,1,.001); %This matrix takes up only 12 Mb
>> whos S
Name Size Bytes Class Attributes

S 1073741822x1 12878636 double sparse


>> Sr=reshape(S,2,[]); %But this reshaped version exceeds memory limits

??? Error using ==> reshape
Out of memory. Type HELP MEMORY for your options.