Question on ismembc and any function
6 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Jan
on 26 Feb 2014
Edited: Jan
on 26 Feb 2014
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?
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!