好的,我有以下代码,我希望线从城镇列表中的一个点移到另一点。但是plot命令不能正常工作,有什么想法吗?
clear;
clc;
numberOfTowns = input ("How many towns should be visited? ");
%Initalization of variables
if ( !exist("numberOfTowns", "var") == 1 )
numberOfTowns = 10; %Default value for numberOfTowns
endif
%Distances matrix
distances = randi([0, 100], numberOfTowns, numberOfTowns); %initialize distances matrix
distances (logical(eye(numberOfTowns))) = 0; %Make diagonal zeros
%Towns List
townsList = 1: numberOfTowns; %initialize townsList
townsList = randperm(length(townsList)); % shuffle the vector
%Points of towns
townsPointsX = randi ([0, 100], 1, numberOfTowns);
townsPointsY = randi ([0, 100], 1, numberOfTowns);
plot (townsPointsX, townsPointsY, 'or');
hold on
for ( i = 1:(numberOfTowns - 1) )
plot ( [ townsPointsX (townsList (i)) townsPointsX (townsList (i + 1)) ], [townsPointsY (townsList (i)) townsPointsY (townsList (i + 1))], 'g' );
endfor
hold off
endfunction