2

这可能是一个愚蠢的问题,但我不太擅长 matlab,而且我不知道如何从用户那里获得输入。我正在编写应该n从用户那里获取节点及其坐标的代码,然后找到哈密顿路径。这是我的想法,请告诉我我错在哪里。

n=input('\nPlease enter the number of nodes: \n')
for i:1:n
  pos[]=input('\nPlease enter their coordinates. \n')
end
x=pos(:,1);
y=pos(:,2);

提前致谢。

4

1 回答 1

3

我想你的意思是

pos[]=input('\nPlease enter their coordinates. \n')

应该改为

pos(i)=input('\nPlease enter their coordinates. \n')

但 pos 不会有两列,所以也许这更好:

for i:1:n
  x(i)=input('\nPlease enter X coordinate. \n')
  y(i)=input('\nPlease enter Y coordinate. \n')
end

然后存储在单个数组中,在循环之后执行以下操作:

A = [x, y]
于 2013-04-12T12:57:41.753 回答