Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Matrix dimension error while trying to eliminate an element in cell array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
Antworten (0)
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!