0

通常、次の方法でループを使用して行っている計算を実行したいと思います。

% d is a vector with size of k.
% X_ind, Z_ind is a vector with size k. %(have indexes only in the range of m*n)
% c is a vector with size k.
% each value of d(i) , c(i) (i=1:k) mataches the indexes X_ind(i),Z_ind(i)
% **In General**:
% N represents amplitudes (some negative,some positive) that sum up.
% M(:,:,1) reperesents a result that is weighted with M(:,:,2)
% M(:,:,1) and M(:,:,2) can be separate matrices

k=length(d); %also k=length(c), k=length(X_ind), k=length(Z_ind)
n=512 % can be any number
m=256 % can be any number
M=zeros(m,n);
N=zeros(m,n,2)+eps;    
for i=1:(m*n)
    x=X_ind(i);
    z=Z_ind(i);

    M(z,x)=M(z,x)+d(n);

    a=abs(M(z,x)); % a is a scalar

    N(z,x,1)=(N(z,x,1).*N(z,x,2)+c(n)*a)/(N(z,x,2)+a);
    N(z,x,2)=N(z,x,2)+a;
end

代わりに accumarray コマンドを使用します。

M=accumarray([Z_ind X_ind], d];

N=???

そのようにNを計算する方法を誰かが指摘できますか?

4

0 に答える 0