0

I have a octave script (script.m) file with the following code:

if length(argv()) > 0
     s = argv(){1};
else
     s = "";

In octave command window, pwd is set to the script directory. From command window, how can I run script.m with one, two or no arguments?

I am using Octave (GUI) in windows.

1 Answer 1

1

An endif is missing at the end but here we go:

if length(argv()) > 0
  s = argv(){1};
else
  s = "";
endif
s

With no argument:

$ octave script.m
s =

With one argument:

$ octave script.m foobar
s = foobar

With two arguments (the second goes to nirvana because you don't use it in your script):

$ octave script.m foobar baz
s = foobar
Sign up to request clarification or add additional context in comments.

3 Comments

I am using Octave (GUI) in windows. Here it says that 'octave' is undefined
If you browse to your Octave installation folder (I guess it's c:\Octave) you'll'' find a octave-cmd.bat or vbs. 'octave´ should run from these directly. If you want to run octave from a windows "cmd" window you'll have to set the PATH so that it includes the /bin directory. Have a look at the before mentionen .bat and .vbs, they show you how to set it
actually, I was using octave.bat. The error that I am getting is from that window.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.