Running files: path problem?

I have a problem that has occurred on both my PC and Laptop versions of MATLAB. Neither will now run .m files which are entered at the command line. For example, let's set up a simple m file, %check.m x=2; y=x^2
This is called check.
Previously I would just enter >> check on the command line and the file would run.
Now the response is:
??? Undefined function or variable 'check'.
Following previous threads, this seems to be related to the path that MATLAB looks for in finding the file, here check; but check is in the current folder displayed by MATLAB and is saved in that folder. Typing path responds as MATLABPATH, with the current folder listed first and then a number of other paths differing only in referring to \toolbox\matlab\general etc.
My puzzle is threefold: I. Why won't the files now execute from the command line. 2. Have I inadvertently changed the path, if so how? 3. Has MATLAB changed this routing to find the file compared to previous versions?
I have resorted to an old version of MATLAB to run my files, where no such problems have occurred, but some tips on getting the recent versions working would be very helpful.

2 Comments

In the Command Window, type which check -all and observe the results. If you see something like 'check' not found then verify that the check.m file is in fact in a folder that is included in the search path and not in a sub-folder off of some folder in the search path.
Joseph Cheng
Joseph Cheng on 10 Jul 2014
Edited: Joseph Cheng on 10 Jul 2014
There are some quick questions that should help debug this issue.
  1. after running it from the editor (using the green run button) are you able to re-run the program from the command line?
  2. If you use the run button (or F5) when not in the right folder does it ask to change folders?
  3. Are you able to run m files from the default 'C:\Users\ (your user name) \Documents\MATLAB\' folder?
  4. Have you tried clicking on the set path button (in the newer matlabs or the file->set path for older versions) and resetting it to the default.
  5. lastly try using addpath() to temporarily add it to the path list and see. Not a solution to your problem but may give some clues.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 10 Jul 2014
Type filebrowser to bring up the panel with files in the current folder. It will have files in the same folder as your current folder in the drop down list at the top of MATLAB. Do you see your file in there? It should be there if you saved your file to the current folder and didn't browse to save it in some other folder. So you should just be able to run it by hitting F5, typing check, or clicking the green triangle. If you don't, then run psr.exe from the start menu and record your screen, save the session (it will save as a zip file), and attach it here as a zip file with the paper clip icon.

1 Comment

Thank you for you answer. Following the steps:
type file browser - yes, the file is there;
tried run on the file, response, as before:
??? Undefined function or variable 'check'.
ran psr.exe, file attached (screencapture2 I hope, ignore other files).
Hope this is clear enough to read.
Many thanks for your help.

Sign in to comment.

Categories

Asked:

on 10 Jul 2014

Commented:

on 10 Jul 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!