Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Undefined function or variable - for no reason...
Replies: 27   Last Post: Jan 28, 2014 9:41 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Frank

Posts: 115
Registered: 12/27/07
Re: Undefined function or variable - for no reason...
Posted: May 30, 2012 12:19 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Øyvind" wrote in message <jq57d4$8be$1@newscl01ah.mathworks.com>...
> John:
> You are right, it is possible to have the same name and make it work. BUT it is also a chance that this will produce errors that are hard to figure out.
>
> Here is an explanation: http://www.mathworks.com/support/solutions/en/data/1-3NP7VQ/index.html
>
> Oyvind


------------------------------------------------------------------------------------------

I'm not quite sure what the problem here turned out to be or how you or TMW solved it, but many, many versions ago when MATLAB first created the ?MATLAB? directory under ?Documents? (on Windows systems), I added the following code to the beginning of my ?startup.m? (in ?toolbox\local?) and have never had problems since (unless I created a new subdirectory while I was running MATLAB and forgot to tell MATLAB about it). The code could probably be improved, and updated to take advantage of new features and syntax, but since it only needs to run once when I launch MATLAB, and it still runs correctly, I haven't changed it significantly unless changes in MATLAB versions required them. (I have all my user files and data collected in a single ?Documents\MATLAB\? subdirectory ?My_Files? and its subdirectories.)

To use it, change the ?workfiles = 'My_Files';? line to the subdirectory name you use. MATLAB will find and run new ?.m? files and find new data files created while MATLAB is running if they?re somewhere in an existing subdirectory of ?My_Files?.


% ================== START ?ADD WORK FILES TO PATH? ==================

pathmat = path;

findpath = strfind(pathmat,'\MATLAB');

firstpath = [pathmat(1,1:findpath(1)+6) '\'];

firstpathdir = dir(firstpath);

dirnamemat = char(firstpathdir.name);

for k1 = 1:size(dirnamemat,1)
if isdir(dirnamemat(k1,:)) && isempty(findstr(dirnamemat(k1,:),'.'))
workpath = [firstpath dirnamemat(k1,:) '\'];
workdir = deblank(dirnamemat(k1,:));
end
end

workfiles = 'My_Files'; % Subdirectory and its subdirectories under 'Documents\MATLAB\' where I have my user files

newpath = genpath(workdir);

scanpath = textscan(newpath,'%s','Delimiter',';');

charpath = char(scanpath{:});

for k1 = 1:size(charpath,1)
filepath(k1,:) = [firstpath '\' charpath(k1,:)];
end

for k1 = 1:size(charpath,1)
% fprintf(1,'\t%3d %s\n',k1,filepath(k1,:))
addpath(filepath(k1,:),1)
end

fprintf(1,'\n\t\tWORK FILES "%s" ADDED TO ?MATLABPATH? ... \n', workfiles);

% ================== END OF ?ADD WORK FILES TO PATH? ==================


Date Subject Author
6/11/10
Read Undefined function or variable - for no reason...
Theophane
6/11/10
Read Re: Undefined function or variable - for no reason...
Steven Lord
8/10/10
Read Re: Undefined function or variable - for no reason...
teki
8/10/10
Read Re: Undefined function or variable - for no reason...
Shanmugam Kannappan
8/10/10
Read Re: Undefined function or variable - for no reason...
teki
8/10/10
Read Re: Undefined function or variable - for no reason...
Jan Simon
8/10/10
Read Re: Undefined function or variable - for no reason...
teki
8/10/10
Read Re: Undefined function or variable - for no reason...
Jan Simon
8/10/10
Read Re: Undefined function or variable - for no reason...
teki
9/17/10
Read Re: Undefined function or variable - for no reason...
Øyvind
9/22/10
Read Re: Undefined function or variable - for no reason...
Jeremy Lagorse
9/23/10
Read Re: Undefined function or variable - for no reason...
Øyvind
4/7/11
Read Re: Undefined function or variable - for no reason...
Shai
6/28/11
Read Re: Undefined function or variable - for no reason...
nick
3/23/12
Read Re: Undefined function or variable - for no reason...
Hye Young
8/10/10
Read Re: Undefined function or variable - for no reason...
us
8/10/10
Read Re: Undefined function or variable - for no reason...
Walter Roberson
11/12/13
Read Re: Undefined function or variable - for no reason...
Rafa
11/12/13
Read Re: Undefined function or variable - for no reason...
Steven Lord
5/30/12
Read Re: Undefined function or variable - for no reason...
Di
5/30/12
Read Re: Undefined function or variable - for no reason...
Øyvind
5/30/12
Read Re: Undefined function or variable - for no reason...
John D'Errico
5/30/12
Read Re: Undefined function or variable - for no reason...
Øyvind
5/30/12
Read Re: Undefined function or variable - for no reason...
John D'Errico
5/30/12
Read Re: Undefined function or variable - for no reason...
Frank
1/27/14
Read Re: Undefined function or variable - for no reason...
Yilin
1/28/14
Read Re: Undefined function or variable - for no reason...
Steven Lord
1/28/14
Read Re: Undefined function or variable - for no reason...
Yilin

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.