matlab 矩阵稀疏化,性能 – Matlab:构建非常大的稀疏带矩阵,内存和计算量都很小...

我可以建议另一种方法.

什么会反对使用2 * N-by-1向量,可以通过对索引的简单转换进行索引?像这样:

% Oli's solution, and your request: NxN matrix

N = 100;

s = 30;

pdf = @(x) 1/(sqrt(2*pi)*s)*exp(-0.5*(bsxfun(@minus,x(:),1:N)/s).^2);

A = pdf(1:N);

% My solution: 2*N x 1 vector

B = exp(-0.5*((-N:N)/s).^2) / s/sqrt(2*pi);

诀窍是找到一个不错的通用索引规则.这是怎么做的:

% Indexing goes like this:

fromB = @(ii,jj) B(N+1 + bsxfun(@minus, jj(:), ii)).';

ii = 30;

jj = 23;

from_A = A(ii,jj)

from_B = fromB(ii,jj)

ii = 1:2;

jj = 4:6;

from_A = A(ii, jj)

from_B = fromB(ii,jj)

结果:

from_A =

0.012940955690785

from_B =

0.012940955690785

from_A =

0.013231751582567 0.013180394696194 0.013114657203398

0.013268557543798 0.013231751582567 0.013180394696194

from_B =

0.013231751582567 0.013180394696194 0.013114657203398

0.013268557543798 0.013231751582567 0.013180394696194

我相信你可以弄清楚如何做冒号索引和使用end关键字:)

你可能感兴趣的:(matlab,矩阵稀疏化)