フィルターのクリア

Question on ismembc and any function

4 ビュー (過去 30 日間)
jana
jana 2014 年 2 月 26 日
コメント済み: jana 2014 年 2 月 26 日
Hi, I am having a problem using the ismembc and any function. Here's the code that I wrote:
while ~isempty(XH{i})
L = false(n, n);
seccost = zeros(n, n);
for ii = 1:n
for jj = 1:n
L(ii,jj) = any((ismembc(XH{i},Sc{ii,jj}))); % my problem function!!!
if L(ii,jj) == 1
seccost(ii,jj) = costs(ii,jj);
seccost(i,j) = 0;
seccost(j,i) = 0;
else
seccost(ii,jj) = 0;
end
end
end
end
this works fine for small values of n, however as n increases (n = 3000), my code takes a lot of time. I've to use seccost matrix thus generated to calculate the shortest path using graphshortetspath function. I was wondering if you have a better idea to increase the efficiency of my code. I was initially using ismember function, but I changed it to ismembc function as it is faster. But it is still not helping.

回答 (1 件)

Jan
Jan 2014 年 2 月 26 日
編集済み: Jan 2014 年 2 月 26 日
Omit overwriting zeros by zeros:
L = false(n, n);
seccost = zeros(n, n);
for ii = 1:n
for jj = 1:n
L(ii,jj) = any((ismembc(XH{i},Sc{ii,jj}))); % my problem function!!!
if L(ii,jj) == 1
seccost(ii,jj) = costs(ii,jj);
end
end
How large are the elements of XH and Sc?
  1 件のコメント
jana
jana 2014 年 2 月 26 日
Jan,
XH is a cell array of size 1xn where n = 3000 and Sc is of size n x n with n = 3000 and it is again a cell array. Both of these variables contain a set of numbers example: XH{1} = [1,2,3] and Sc{1,2} = [1,3,4]. I dont think by omitting overwriting zeros by zeros is going to help much. Is there a better way of writing the above code. I am new to matlab and this was the best I could think of.

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by