matlab在循环之前分配上三角稀疏矩阵

时间:2015-05-01 06:42:56

标签: matlab for-loop memory-management sparse-matrix

如何分配稀疏矩阵,其中上三角形部分为非零,下三角形部分为零?我目前正在查看spalloc()函数

U = [0.046805;0.047415;0.048025;0.046805;0.047415;0.048025]; % small example here this can be very large!
V = [-0.000305;-0.000305;-0.000305;-0.000935;-0.000935;-0.000935]; % small example here this can be very large!
N = length(U);
A=zeros(N); % allocate upper triangular diagonal sparse matrix here
B=zeros(N); % allocate upper triangular diagonal sparse matrix here
for i=1:N-1
    for j=i+1:N
        A(i,j)=4*U(i)*U(j)/((U(i)+U(j)).^2+(V(i)-V(j)).^2);
        B(i,j) = sqrt((U(i)*U(j))/(A(i,j)));
    end
end
% Later do some maths with the non-zeros 

0 个答案:

没有答案