How can I improve Matlab perfomance for this code?
古いコメントを表示
Adn and custo are same size vectors, with a length of 10252 elements (length(Adn)=10252). Every row value in custo corresponds to the cost of the same row value in Adn . I'm trying to get the sum of all the possible combinations for the values in Adn and analyze the cost of that combination. From the Adn combinations, I am just interested in the ones that sum to a specific interval (which is lower than sum(A) and greater than sum(A)*0.9). A is previously written in the code, so it doesn't matter now. Then I want to store the combinations and their equivalent costs ( custoAll ) in two new vectors.
nA=numel(Adn);
for k1=1:nA
B=combntns(Adn,k1);
C=sum(B,2);
E=combntns(custo,k1);
F=sum(E,2);
D=find(((C<(sum(A)))&(C>(sum(A)*0.9))));
if ~isempty(D)
combinations=[combinations; B(D,:)];
custoAll=[custoAll; F(D)];
end
end
This code is taking very long though. I know I should preallocate the variables combinations and custoAll otherwise they will change size in every iteration and it'll take longer to run, but I haven't been able to find a good way to do it, since Adn is already so huge. Does anybody have an insight on this?
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!