简体   繁体   English

从终端使用 Octave 运行 function

[英]Run a function using Octave from terminal

I want to run a function - let's say test - inside my test.m file.我想在我的 test.m 文件中运行 function - 比方说测试。 I want to run this function using Octave from terminal.我想从终端使用 Octave 运行这个 function。 So, it should be something like:所以,它应该是这样的:

$>/Users/me/octave/bin/octave test(param1,param2)?

How can I accomplish this?我怎样才能做到这一点? I can do that in Matlab. But I didn't find a way in Octave.我可以在 Matlab 中做到这一点。但是我没有在 Octave 中找到方法。

You can use octave --eval CODE您可以使用octave --eval CODE

Octave's docs on this can be foundhere . Octave 的相关文档可以在这里找到。 To run a function with input args:要使用输入参数运行 function:

  1. In Terminal cd to your working directory.在终端cd到您的工作目录。
  2. Type octave to open an interactive session.键入octave以打开交互式 session。
  3. ls to check that your function's file is in your working dir, cd to the dir if not. ls检查你的函数文件是否在你的工作目录中,如果不在,则cd到该目录。
  4. Type the function's name immediately followed by the input args in brackets in the correct order, Eg: >foo(100) .键入函数名称,紧接着以正确顺序在方括号中键入输入参数,例如: >foo(100) Your function will then run, spitting out whatever you print as well as all the results for lines of code not ending with ;然后你的 function 将运行,吐出你打印的任何内容以及所有不以;结尾的代码行的结果。 . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM