I have a question about the way that the open() function and how / why it differs from that matlab function.
When I have a script in my path but not my current directory and I want to open it, in matlab i do:
but in octave this does nothing, if I add the extension like:
In matlab this will also open the script in my path, but in octave, a window will popup prompting me to create a new file with that name.
To achieve this in octave I do
I think typing out the entire path would also work.
this also applies to when it uses the syntax like:
open myscript % this is an error
open myscript.m % this is an error
In matlab all of these cases do the same thing. so, my question is why is it like this?
Would it be appropriate to propose that the behavior be changed to be more matlab-like? or is this intentional? I could see someone preferring the current behavior for prompting the creation of a local file, but for me I think it’s way more useful to be able to quickly open a script with the
syntax, since it’s the simplest to type.
edit myscript should work in Octave and in Matlab.
here’s an example:
example.m (546 Bytes)
This uses fwrite to make a script in a folder, then I add that folder to the path, then I show 3 ways that I’d try to open it.
if this works for you, perhaps it’s version dependent? I’m using:
ans = 7.1.0
open hello_world, use
For anyone that doesn’t like to download that script, its content is:
% if I have a script in my path that I'm using and want to debug...
fid = fopen('Desktop/my_scripts/hello_world.m','a')
hello_world % this verifies that the script is in my path
%I'll use the open() function in the command window when I want to debug that script
open('hello_world') % here nothing happens
open('hello_world.m') % this create a popup prompting me to create a new file
open(which('hello_world')) % the behavior that I want is:
Sounds like a bug. These days, Octave generally tries to be maximally Matlab compatible, especially with the behavior of functions that are defined by Matlab. Matlab is pretty clear about
open doing the “search the Matlab path for code files if the argument has no file extension” behavior. So we probably want to make Octave’s
open do that, though it’s low priority.
But I’d recommend you just use
edit instead of
open for this functionality. That’s the command for opening a source code file or code definition.
open is a more file-oriented thing that supports multiple file types and extensibility.