How can I create 3D matrix from 2D matrix by diagonal of coulumn variables?

조회 수: 1 (최근 30일)
Szabó-Takács Beáta
Szabó-Takács Beáta 2015년 5월 19일
댓글: Matt J 2015년 5월 19일
I have a pr(17859x10957) matrix. I would like to create a 17859x17859x10957 matrix by the diagonal of every column. I tried the following solution:
for j=1:10957
rr(:,:,j)=diag(pr(:,j));
clear rr
end
This solution consumes too much physical memory. Can someone offer me a better solution?
  댓글 수: 1
Matt J
Matt J 2015년 5월 19일
I don't think you want the "clear rr" command in there. That will erase the hard work done by every pass through the loop. It will also de-allocate rr (I hope you have pre-allocated it before the loop) making the loop run very slowly.

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2015년 5월 19일
Depending on what you plan to do with rr, you could use my ndSparse class to maintain it in sparse form,

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by