I'm attempting to execute a script from the shell (Mac OS) using Octave, and this is exactly what I type:
$ open -a octave "my_script.m"
The result, is that Octave (the full application in the GUI) opens and doesn't run the script.
Ideally, I'd like Octave to actually run in Terminal (without the GUI), and execute whatever commands and scripts I type there, including, as noted above, an entire script stored in a .m file.
I also tried the following:
$ octave-cli my_script.m
Which produces the following error:
-bash: octave-cli: command not found
I installed Octave through a DMG file linked to on the official GNU website.
The command you're looking for is called octave-cli, and there's no need to open, just octave-cli my_script.m.
Related
I installed an application named lqns in the path: /home/robb/Research/dist/lqns-6.2/lqns (lqns is a folder containing the executable lqns). I want the program to be executed in command line simply calling lqns in the shell, I solved this adding to the file ~/.bashrc the line:
export PATH=$PATH:/home/robb/Research/dist/lqns-6.2/lqns
And it works with no issue. I am now trying to execute this program inside a Matlab script, running:
[status, ~] = system("lqns " + filename, '-echo');
Where filename is the path of an input file. I get the error message:
/bin/bash: line 1: lqns: command not found
Running the exact same command with the shell I get no error: the program runs with no problem generating the relative output.
Running getenv('PATH'); in Matlab and printenv PATH on my OS shell I indeed get two different results: Matlab does't have the path to lqns. I even tried editing manually the files /etc/environment, /etc/bash.bashrc and /root/.bashrc, with no result. How can I solve this issue?
you need to launch matlab by typing matlab in a terminal, not by double clicking on its shortcut from your desktop. (or even typing ./matlab in a terminal from your desktop)
it's up to the operating system to determine what double clicking does, and it's not guaranteed to execute most of your shell initialization scripts (or even launch it from the correct shell to begin with).
more info at Why are environment variables not resolved when double-clicking .desktop file?
I use the system/unix command on Matlab in order to run an external program via the command line. I want to execute it via an alias define in .zshrc on my computer. Unfortunately, the alias seems to be not available.
Example with ll
on a terminal: which ll gives ll: aliased to ls -lh
on Matlab: unix('ll') gives zsh:1: command not found: ll
I check if I used the right shell: unix('echo $SHELL') gives /usr/local/bin/zsh.
I have add setopt aliases in my .zshrc but it changes nothing. Is it possible to check which startup files is used when you open a non interactive shell?
The ~/.zshrc seems to be not loaded in the non interactive case. The solution consists in loaded aliases and added setopt aliases in ~/.zshenv. See this for instance.
I am trying to open multiple cygwin terminals and run a .exe file in each of them through octave GUI. I was able to do this in MATLAB, but the exact same code in octave does not work.
Code used :
dos(['C:\cygwin64\bin\mintty.exe /bin/bash -login ./testtorun_ig1_1.sh']);
dos(['C:\cygwin64\bin\mintty.exe /bin/bash -login ./testtorun_ig1_2.sh']);
dos(['C:\cygwin64\bin\mintty.exe /bin/bash -login ./testtorun_ig1_3.sh']);
dos(['C:\cygwin64\bin\mintty.exe /bin/bash -login ./testtorun_ig1_4.sh']);
testtorun_ig1_1 has the command to open a .exe file.
What happens in octave is, initially one cygwin terminal open and runs the .exe file. After the application completes and exits, cygwin terminal closes and opens the next cygwin terminal opens and runs the second .exe files. I want to be able to run 4 cygwin terminals at a time, which is what happens in MATLAB but not in octave
In Octave, dos waits until the external command completes before executing any more commands.
Octave waits for the external command to finish before returning the exit status of the program in status and any output in text.
If you want to evaluate the external commands asyncronously, you should use the system command with the 'async' input argument
id = system('C:\cygwin64\bin\mintty.exe /bin/bash -login ./testtorun_ig1_1.sh', 0, 'async')
I'm using Ubuntu system. To run MATLAB script at launch, I can type matlab -nodesktop -r "run ./my_program.m".
How can I achieve the same function on Octave, like octave --no-gui -some_command?
I've read this post and this post. They did not answer my question.
As mentioned in one of the comment, one solution is:
octave --persist my_program.m
Currently looks like it is enough to say for script (not plain function)
octave my_program.m
Also if you have octave installed in your path you could and in the beginning of script as the first line the desired interpreter (works for python, bash, whatever), for example for default location :
#!/usr/bin/octave
and you can run them without even adding the octave in front... just the script name....
For Windows users:
I see it's a bit harder, since there's no "octave.exe" file.
I do have:
"C:\Program Files\GNU Octave\Octave-6.4.0\mingw64\bin\octave-cli-6.4.0.exe"
which works after adding both parent directories
"C:\Program Files\GNU Octave\Octave-6.4.0\mingw64\bin"
and
"C:\Program Files\GNU Octave\Octave-6.4.0\mingw64"
to PATH.
All this happens automatically in the startup script which is the normal entry point of the SW:
"C:\Program Files\GNU Octave\Octave-6.4.0\octave.vbs"
Finaly, after adding all to path I run it like this:
"C:\Program Files\GNU Octave\Octave-6.4.0\mingw64\bin\octave-cli-6.4.0.exe" "C:\MatlabScripts\matlabScript1.m" c:\temp\myCuteImage [example for prm]
I am trying to run a Matlab script from Windows command prompt but I can't execute it sometimes. The script runs fine when manually launched. Matlab version is 2011a and Windows is Server 2003 SP2. Details:
Script mytask.m is located inside say E:\Production\Project. This is SAVED on Matlab's path.
When I place mytask.m inside bin folder, it executes fine by the command:
`C:\Program Files\MATLAB\R2011a\bin>matlab -r mytask`
If you delete it and try to access it at its original location, the script doesn't run although Matlab editor window is launched:
`C:\Program Files\MATLAB\R2011a\bin>matlab -r "E:\Production\Project\mytask"
Any suggestions please? Thanks.
The syntax for matlab -r is
matlab -r "statement"
In other words, you need to provide some executable commands as the statement. For example:
matlab -r "run E:\Production\Project\mytask"
However, it seems that matlab does not load the customized paths in this way. If you have some customized paths, you probably have to define them in startup.m and place this startup.m in the directory where you invoke matlab.
I didn't check myself, but if you define E:\Production\Project\ as the path in startup.m, you probably can run matlab -r mytask without problem, as mytask will be recognized as a user function/script.
A simple example of startup.m
path(path, 'E:\Production\Project\');