Help. Why does my matlab code work one moment, and then suddenly stops working?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
It just suddenly keeps runnning forever. Please help.
%%Initial Populations
%%------------------------------------------------
%Path Selection
clear start_node end_node Dist Fit
fprintf('Enter Integer Only');
start_node=input('Start Node: ');
end_node=input('End Node: ');
dist = zeros(49,49);
%import distance values from excel
for i = 1:168
dist(Node1(i,1), Node2(i,1)) = Distance(i,1);
end
clear path;
n=2;
path(1,1)=start_node;
start=start_node;
dist1=dist;
total_dist=0;
%o=0;
%r=0 might not need
while start ~= end_node
clear store_value chosen;
k=1;
%possible next node number
for j=1:49
if dist1(start,j) > 0
store_value(k)=j;
k=k+1;
end
end
%random choosing for next node number
idx = randperm(numel(store_value));
chosen = store_value(idx(1));
%Should never have this situaiton since 2D analysis only
%if chosen - start == 25 & r==0;
% r=1;
%elseif chosen - start == 25 && r==1
% while chosen - start == 25
% idx=randperm(numel(store_value));
% chosen = store_value(idx(1));
% end
%r=0;
% end
%Path
path(1,n) = chosen;
n=n+1;
start = chosen;
end
%End of Path Selection
%%Path Elimination
%---------------------------------------------------
a = numel(unique(path));
b = numel(path);
path1 = path;
while numel(path) ~= numel(unique(path))
h=0;
x=numel(path);
for h=1:x
if h<x-2 && path(1,h) == path(1,h+2)
path([h+1,h+2]) = [];
x=numel(path);
elseif h == x-1 || h == x
break;
end;
x=numel(path);
end
k = 1;
for j = 1:x
if j < x-2 && path(1,j) == path(1,j+2)
k = k+1;
end
end
if k == 1;
break;
end
end
path3 = path;
while true
pathhist = histcounts(path3, [unique(path3), Inf]);
duplicate = path3(find(pathhist > 1, 1)); %find identical digit
if isempty(duplicate)
break; %nothing left to remove, exit loop
end
occurences = path3 == duplicate;
path3(find(occurences, 1) : find(occurences, 1, 'last')-1) = []; %delete 1st occurence and anything up to last occurence
end
0 comentarios
Respuestas (1)
Image Analyst
el 26 de Mzo. de 2016
I guess you entered something that caused an infinite loop. What inputs did you provide it?
2 comentarios
Image Analyst
el 30 de Mzo. de 2016
It says it doesn't know what Distance is. If you still need help, post the code and workbook to get the Distance values into your program so I can run it.
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!