이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1(최근 30일)
Hari 2016년 10월 26일
마감: Hari 2016년 10월 27일
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 = [];
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;
[a,b] = kShortestPath(netCostMatrix, source, destination,kpaths);
for i = 2:kpaths
if b(1,i) > (1.25 * b(1,1))
a{1, i }=[];
s = a';
t = b';
v = vertcat(v,s);
w = vertcat(w,t);
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
Hari 2016년 10월 26일
편집: Hari 2016년 10월 26일
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?


Community Treasure Hunt

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

Start Hunting!

Translated by