フィルターのクリア

how to decrease time of for loop

1 回表示 (過去 30 日間)
muhammad ismat
muhammad ismat 2018 年 4 月 3 日
コメント済み: muhammad ismat 2018 年 4 月 4 日
if I have data X=[1 3; 1 4; 2 3; 2 6] (where max number in X (6) represent the number of nodes) that represent the edges between nodes of network and i want to calculate the remaining edge =[1 2; 1 5;1 6;2 4;2 5;3 4;3 5;3 6;4 5;4 6;5 6]
thus i calculate the all links(result) then remove X from it.
but when i have max number of nodes (say 8000) , the following code take a long time . So I want another code take a short time.
u=max(max(X)); %u is the number of nodes in graph
result = zeros(u*2,2);
ri = 1;
for ii=1:u
for jj = ii+1:u
result(ri,:) = [ii jj];
ri = ri+1;
end
end
  1 件のコメント
muhammad ismat
muhammad ismat 2018 年 4 月 4 日
isRowToRemove = ismember(result,X,'rows');%test result is member in X or not, it is removed if it is member in X.
result(isRowToRemove,:) = [];

サインインしてコメントする。

回答 (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