[英]Pass a file name as a command line argument to GNU Octave script
在可执行的Octave脚本中,我想传递包含矩阵的文件的名称,并使gnu octave将该文件信息作为矩阵加载。 我怎么做?
这是脚本应该是什么样子
#! /usr/bin/octave -qf
arg_list = argv()
filename = argv{1} % Name of the file containing the matrix you want to load
load -ascii filename % Load the information
传递的文件将是一个矩阵,其中包含任意大小的矩阵,例如2x3
1 2 3
5 7 8
在命令行,脚本应该以./myscript mymatrixfile
运行,其中mymatrixfile
包含矩阵。
这是我尝试执行上面用八度音程编写的脚本时得到的
[Desktop/SCVT]$ ./octavetinker.m generators.xyz (05-14 10:41)
arg_list =
{
[1,1] = generators.xyz
}
filename = generators.xyz
error: load: unable to find file filename
error: called from:
error: ./octavetinker.m at line 7, column 1
[Desktop/SCVT]$
generators.xyz
是包含我需要的矩阵的文件
这应该工作:
#!/usr/bin/octave -qf
arg_list = argv ();
filename = arg_list{1};
load("-ascii",filename);
当您编写行load filename
您指示加载函数加载文件名“filename”。 也就是说,你做了相当于load('filename');
的事情load('filename');
。
在MATLAB和Octave中,函数“foo”后跟一个空格,然后单词“bar”表示bar将作为字符串提交给foo。 即使bar是工作空间中的已定义变量,也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.