Help open
6 views (last 30 days)
Show older comments
Hi, I was trying to write a command inside a function to open a script and I digited :
open('filename.m')
after I run the script pressing F5, matlab is not opening scripts allowing to modify them anymore! I mean, when I double click on a script in the " current folder" bar, it always opens the same script!
In the command window the following is displayed :
Warning: The input to STR2FUNC "C:\Users\Andrea\Desktop\Guidance_Andre\Before.m" is not a valid function name. This will generate an error in a future release. > In edit at 36 In general\private\openm at 12 In open at 158 In uiopen at 196
edit : is the script that is always opened, no matter what script I double click on Before.m is the file I mentioned when I used the open function: I digited open('Before.m')
PLEASE HELP ME !!!!!
0 Comments
Answers (3)
Sean de Wolski
on 26 Aug 2011
edit is a very powerful and useful builtin MATLAB function. Your script named edit is overwriting this making open fail when it calls edit. Open is expecting MATLAB's edit, it's receiving yours and it's not happy. Unhappy MATLAB means unhappy you!
0 Comments
Fangjun Jiang
on 26 Aug 2011
Use edit('filename.m') is safer.
open('filename.m') may execute the .m file. It depends whether you have a openm.m file defined.
help open
0 Comments
Walter Roberson
on 26 Aug 2011
The first time you run a function, MATLAB will preprocess it, and it will associate the preprocessed version with the function for efficiency. If you then edit the function, MATLAB may not notice that it has been edited and so might continue to use the old version.
If you are using a sufficiently new MATLAB (I'm not sure which release exactly, might be since 2010b or possibly since 2010a), the same thing applies to scripts, not just functions.
In order to get MATLAB to recognize the change, it might be necessary to use the rehash() command or to use the clear() command specifying the name of the function or script.
This issue can be especially noticeable if you use function handles and edit a function that another function has an active handle to.
0 Comments
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!