如何从终端 运行 带有多个参数(包括矩阵)的 ocatve 命令?

How to run an ocatve command from the terminal with several arguments including a matrix?

我想 运行 来自终端的带有多个参数的八度脚本。

考虑函数

function matrixMultiply (A, x)
  result = A * x ; 
  presult = sprintf('%s %s\n', 'A * x =', mat2str(result));
  printf ("\a%s\n", presult);
endfunction 

如何从终端调用此函数。我尝试使用

arg_list = argv ();
for i = 1:nargin
  printf (" %s", arg_list{i});
printf ("\n");
endfor

在一个单独的脚本中,运气不好。

我怎么能运行

$ octave  matrixMultiply(eye(2) , [3;4])

从终端?

您可以在不使用 argv ()

的情况下调用您的函数文件

文件matrixMultiply.m:

function matrixMultiply (A, x)
  result = A * x ; 
  presult = sprintf('%s %s\n', 'A * x =', mat2str(result));
  printf ("\a%s\n", presult);
endfunction 

来自终端:

$ octave --eval "matrixMultiply(eye(2) , [3;4])"
A * x = [3;4]