Help. Why does my matlab code work one moment, and then suddenly stops working?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Image Analyst
2016년 3월 26일
I guess you entered something that caused an infinite loop. What inputs did you provide it?
댓글 수: 2
Image Analyst
2016년 3월 30일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!