从 Octave 中的命令 window 以外的其他地方获取输入

Getting input from somewhere other than the command window in Octave

我是 Octave 的初学者。我需要制作一个关于矢量的程序,我需要用户输入来绘制矢量。我可以从命令 window 获得输入,但我需要它像图 window 一样,我希望它弹出。有办法吗?

使用inputdlg()

您可以使用inputdlg()函数轻松创建字符串和数字数据的图形输入界面。这里有一个简单的例子:

myinp = inputdlg({'width','height'},'Please input data!',1,{2.5,320.9})

这将创建以下对话框:

按确定后 returns 结果如下(取决于您的输入):

myinp =
{
  [1,1] = 2.5
  [2,1] = 320.9
}

使用 addlistener()

以上解决方案创建了一个弹出式输入对话框,可能不是您要查找的内容。要根据鼠标坐标获取输入,您可以在当前轴发生变化时使用 addlistener() function to get the currently selected point coordinates from axes object's currentpoint 属性。

% Create a new axis system in current window
ax = axes();
% Define a listener function that does something with the selected points
listener = @(ah) display(get(ah,'currentpoint'));
% Add Listener to current axis property
addlistener(ax,'currentpoint',listener);

无论何时单击您的轴系统,您都会在控制台输出上看到当前坐标。当然这还不能完全解决你的要求,还有一些功课需要你做。

使用 ginput()

使用ginput()函数可以收集一个或多个鼠标点击位置和点击鼠标按钮的次数。