I am trying out to form a sparse matrix but it runs out of memory.Below is the code similar to which I have been working on A=sparse(15000,15000); inb=sparse(eye(10000,10000); it goes out of memory here.
So for forming a identity matrix (inb) I use: inb=sparse(10000,10000); for i=1:1:10000; inb(i,i)=ones; end A(1:10000,1:10000)=inb; it goes out of memory. Is there any way I can get rid of this.

 採用された回答

Andrei Bobrov
Andrei Bobrov 2011 年 8 月 25 日

1 投票

blkdiag(speye(30886,30886),sparse(68709-30886,130478-30886));

1 件のコメント

Samir
Samir 2011 年 8 月 25 日
Thanks Andrei.

サインインしてコメントする。

その他の回答 (3 件)

the cyclist
the cyclist 2011 年 8 月 24 日

3 投票

Try the speye() command.

3 件のコメント

Samir
Samir 2011 年 8 月 24 日
Thanks speye() works fine but when assigning it back to a sparse matrix it goes out of memeory like:
A=sparse(15000,15000);
inb=speye(10000,10000);
A(1:10000,1:10000)=inb;
After the third line it goes out of memory
the cyclist
the cyclist 2011 年 8 月 24 日
I have no problem running that code, and it results in the sparse arrays I expect.
Samir
Samir 2011 年 8 月 25 日
Thanks the cyclist it worked on the computer with high ram.
but actually my this is the real case could you suggest any better option for the following:
aeq=sparse(68709,130478);
inb=speye(30886,30886);
aeq(1:30886,1:30886)=inb;
This is running out of memory now.
I am not getting why MATLAB is not able to include the identity matrix after being sparse also.
Is there any way I can check the number of elements I can include in the array.

サインインしてコメントする。

Walter Roberson
Walter Roberson 2011 年 8 月 25 日

1 投票

aeq=sparse(68709,130478);
generates an empty 68709 by 130478 sparse matrix, with the number of expected non-zero elements set to 0. But then you set a whole bunch of elements to non-zero, which requires reorganizing the sparse matrix as it detects more and more non-zero elements.
If you were to use
aeq=sparse([], [], [], 68709,130478, 30886);
then it would probably have less difficulty.

1 件のコメント

Samir
Samir 2011 年 8 月 25 日
Thankyou but still the same issue:
>> aeq=sparse([], [], [], 68709,130478, 30886);
>> aeq(1:30886,1:30886)=speye(30886,30886);
??? Out of memory. Type HELP MEMORY for your options.

サインインしてコメントする。

Rahul Pal
Rahul Pal 2020 年 8 月 2 日

0 投票

function y = caesar2(ch, key)
v = ' ' : '~';
[~, loc] = ismember(ch, v);
v2 = circshift(v, -key);
y = v2(loc);
end

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2011 年 8 月 24 日

回答済み:

2020 年 8 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by