Info

This question is closed. Reopen it to edit or answer.

Matrix dimension error while trying to eliminate an element in cell array

1 view (last 30 days)
Hari
Hari on 26 Oct 2016
Closed: Hari on 27 Oct 2016
I have written a function loop3 which calls a function kshortestpath (By Meral Sh.). kshortestpath finds k paths (as cell array) between a given source and destination(with first one among them being the shortest path), and the corresponding costs. loop3 is included to iterate the function with only certain 'sources' called terminals and finally list all the paths found. I need to eliminate those paths which have costs more than 1.25 times the shortest path (between a source and destination)
function [v,w ,a,b s,t] = loop3(N)%N represents the total number of nodes in the network
v = [];
w=[];
NT = input('Enter the number of terminals');% to set the number of origins
kpaths = input('Enter the value of k');% number of shortest paths required
for terminal = 1:NT
sub= input('Enter the terminal number');
for x = sub
for y = 1:N
source = x;
destination = y;
if(source~=destination)
[a,b] = kShortestPath(netCostMatrix, source, destination,kpaths);
for i = 2:kpaths
if b(1,i) > (1.25 * b(1,1))
a{1, i }=[];
end
end
s = a';
t = b';
v = vertcat(v,s);
w = vertcat(w,t);
a=[];
b=[];
end
end
end
end
function [shortestPaths, totalCosts] = kShortestPath(netCostMatrix, source, destination, k_paths)
.............. % the code for kShortestPAth comes here......
When I run the code it shows an error:
Index exceeds matrix dimensions.
Error in loop3 (line 16)
if b(1,i) > (1.25 * b(1,1))
Can somebody help me find what is wrong with this code
  2 Comments
Hari
Hari on 26 Oct 2016
Thanks. You are right. Error is displayed when b becomes a null matrix at a particular point in the iteration. Is there a way to improve the code and fix this?

Answers (0)

Community Treasure Hunt

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

Start Hunting!