Octave 选择一个文件?
Octave 有没有好的方法让用户选择输入文件?我在 Matlab 中见过这样的代码,但在 Octave 中不起作用。
基于 GUI 的方法将是首选,但某种命令行选择也可以。如果有某种方法可以在 Matlab 和 Octave 中工作,那就太好了。
我发现 this 用于 Matlab,但它在 Octave 中不起作用,即使您为 listdlg 函数安装 Octave Forge Java 包。在 Octave 中, dir() 为您提供:
647x1 struct array containing the fields:
name
date
bytes
isdir
datenum
statinfo
但我不知道如何将其转换为 listdlg 期望的字符串数组。
Does Octave have a good way to let the user select an input file? I've seen code like this for Matlab, but doesn't work in Octave.
A gui based method would be preferred, but some sort of command-line choice would work also. It would be great if there were some way to do this that would work in both Matlab and Octave.
I found this for Matlab but it does not work in Octave, even when you install Octave Forge Java package for the listdlg function. In Octave, dir() gives you:
647x1 struct array containing the fields:
name
date
bytes
isdir
datenum
statinfo
but I don't know how to convert this to an array of strings listdlg expects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您已经安装了 Octave Forge java 包,因此您可以创建任何 java 类的实例并调用任何java方法。
例如,创建一个
JFileChooser
并调用JFileChooser.showOpenDialog(Componentparent)
方法:顺便说一句。我在安装该软件包时遇到了一些麻烦。
这是 修复 Ubuntu 的问题。这也适用于我的 Debian 测试。
编辑
@NoBugs 回复您的评论:
如果您需要使用listdlg,您可以执行以下操作:
这应该与matlab兼容,但我现在无法测试它。
如果您想选择多个文件,请使用以下命令:
You have already the Octave Forge java package installed, so you can create instances of any java class and call any java method.
For example to create a
JFileChooser
and call theJFileChooser.showOpenDialog(Component parent)
method:Btw. I had some troubles installing the package.
Here is a fix for Ubuntu. that worked also for my Debian Testing.
EDIT
@NoBugs In reply to your comment:
If you need to use listdlg you can do the following:
This should be compatible with matlab, by I cannot test it right now.
If you want to select multiple files use this:
我从未遇到过八度音程中的打开文件对话框。
如果您正在寻找基于 GUI 的方法,也许 guioctave 可以帮助您。我从未使用过它,因为它似乎只适用于 Windows 机器。
一个可能的解决方案是在八度音阶中编写一个小脚本,这将允许用户解析目录并选择这样的文件。
I never came across an open-file-dialog in octave.
If you are looking for a gui based method maybe guioctave can help you. I never used it, because it appears only be available for windows machines.
A possible solution would be to write a little script in octave, that would allow the user to parse through the directories and select a file like that.
我想我会为这个老问题提供更新的答案,因为它出现在其他问题的“相关问题”字段中。
Octave 提供了 uigetdir 和 uigetfile 函数,可以满足您的期望。
Thought I'd provide an updated answer to this old question, since it is appearing in the 'related questions' field for other questions.
Octave provides the
uigetdir
anduigetfile
functions, which do what you expect.