Getting rid of nested loops, follow up

2 ビュー (過去 30 日間)
Daniel Tweed
Daniel Tweed 2017 年 5 月 12 日
編集済み: dpb 2017 年 5 月 12 日
As a follow up to this question for which I got a really great answer:
I have several K x N matrices and I need to calculate new matrices zed and w according to a function which depends on the "rank" in the column if H is sorted descending, i.e. for
H = [1,2;5,6;3,4];
Column ranks are 2,3,1 for both columns.
I had previously asked about an operation that involved addition of elements and was able to adapt the answer to several of the functions I was working with. In some of the functions, I have division of two elements depending on different ranks, which are then used in w and zed in a product over elements type calculation.
Example code:
%all matrices are KxN
w = ones(K,N);
zed = ones(K,N);
for n=1:N
[gain, idx] = sort(H(:,n),'descend');
for i=1:K
for j=1:K
if j ~= i
if j < i
l = L(idx(j),n)/D(idx(i),n);
w(idx(i),n)=w(idx(i),n)*(B(idx(j),n)^2*H(idx(j),n)^2/l)^(-l);
p = P(idx(j),n)/Z(idx(i),n);
zed(idx(i),n)=zed(idx(i),n)*(2*t*B(idx(j),n)*H(idx(j),n)/p)^(-p);
else % j > i
r = R(idx(j),n)/Z(idx(i),n);
zed(idx(i),n) = zed(idx(i),n)*(B(idx(j),n)*H(idx(j),n)/r)^(-r);
end
end
end
end
end
Initially, I thought I could build larger matrices whose columns/rows represented elements of the product, but I can't figure out how to calculate the p,l, and r values as a matrix, and I'm not sure this approach would actually improve performance.
Any solution, help, suggestions, directions, etc. is all really appreciated.

回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by