フィルターのクリア

Question on updating a matrix

1 回表示 (過去 30 日間)
jana
jana 2014 年 1 月 26 日
コメント済み: jana 2014 年 1 月 26 日
I have to create an adjacency matrix every time an if condition is satisfied. I've written the following code.
if ~isempty (Xnew{k,i})
for ii = 1:n
for jj = 1:n
L(ii,jj) = any(ismember(Sc{ii,jj},Xnew{k,i}));
if L(ii,jj) == 1
seccost(ii,jj) = costs(ii,jj);
else
seccost(ii,jj) = 0;
end
end
end
It means that if my set Xnew is empty and if L(ii,jj) is true, then I've to create an adjacency matrix seccost with index ii,jj having some value costs(ii,jj). If L(ii,jj) = 0, the seccost(ii,jj) = 0.
This would be a great code if the size of n is small. But I've a huge value for n and if condition is incurred many times. while creating L, matlab is running out of memory. Please help!!
  3 件のコメント
Jan
Jan 2014 年 1 月 26 日
Please post the error message.
jana
jana 2014 年 1 月 26 日
Thank you Jan, I fixed the error. @ Amit, n is 4000..basically n represents the number of nodes.

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

採用された回答

Jan
Jan 2014 年 1 月 26 日
編集済み: Jan 2014 年 1 月 26 日
Did you pre-allocate L and seccost before the loop?
L = false(n, n);
seccost = zeros(n, n);
  1 件のコメント
jana
jana 2014 年 1 月 26 日
Yes, but it is still not helping.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by