Thread Subject: Matlab path issues

Subject: Matlab path issues

From: Matthew Wade

Date: 18 Aug, 2008 10:13:03

Message: 1 of 9

Hi,

I have an application (GUI) that also is compiled as a
stand-alone executable to be run on other machines.

1. The GUI has some functions that require data to be
saved/called from specific paths, e.g.
C:/Matlab7.1/work/Results

2. To ensure the data is stored in the correct folders, I
use cd pathname, or xlswrite('pathname',data), for example.

3. For some time, I was able to specify the pathname as
only /Results, and this enabled flexibility - now I get
error messages (unknown directory) and cannot trace back
the problem - I now have to use the complete pathname.

4. When I install the stand-alone executable on a new
machine, the problem will occur that I do not have the same
pathname as on the host computer, so when the script cd or
xlswrite is executed with a specifie path, there will be an
error.

Can anyone think of a way to specify folders/directories
that can be generic to any machine? e.g. a function that
creates a folder "Results" in a common and sensible
location (i.e. the Program location f?r the executable and
the work folder for the original -m files).

Thanks
Matt

Subject: Matlab path issues

From: Bill August

Date: 18 Aug, 2008 11:27:46

Message: 2 of 9

> Hi,
>
> I have an application (GUI) that also is compiled as
> a
> stand-alone executable to be run on other machines.
>
> 1. The GUI has some functions that require data to be
>
> saved/called from specific paths, e.g.
> C:/Matlab7.1/work/Results
>
> 2. To ensure the data is stored in the correct
> folders, I
> use cd pathname, or xlswrite('pathname',data), for
> example.
>
> 3. For some time, I was able to specify the pathname
> as
> only /Results, and this enabled flexibility - now I
> get
> error messages (unknown directory) and cannot trace
> back
> the problem - I now have to use the complete
> pathname.
>
> 4. When I install the stand-alone executable on a new
>
> machine, the problem will occur that I do not have
> the same
> pathname as on the host computer, so when the script
> cd or
> xlswrite is executed with a specifie path, there will
> be an
> error.
>
> Can anyone think of a way to specify
> folders/directories
> that can be generic to any machine? e.g. a function
> that
> creates a folder "Results" in a common and sensible
> location (i.e. the Program location f?r the
> executable and
> the work folder for the original -m files).
>
> Thanks
> Matt
Hi
To me I always use the global variable.
Add these code to the main function, and you can use the relative path base on the root dir.
global APP_ROOTDIR ;
APP_ROOTDIR = which('APP_Start') ;
CWIND_ROOTDIR = fileparts(APP_ROOTDIR) ;
if isempty(APP_ROOTDIR)
   warning('Please change directory to the root, then start it again.') ;
    return ;
else
end


Message was edited by: Bill August

Subject: Matlab path issues

From: ControlTheoryPro@gmail.com

Date: 19 Aug, 2008 03:50:29

Message: 3 of 9

Also, use filesep instead / or \ in case you wish to run it on both
Windows and Unix.

Gabe
Wiki Category on MATLAB
http://wikis.controltheorypro.com/index.php?title=Category:MATLAB

Subject: Matlab path issues

From: Matthew Wade

Date: 20 Aug, 2008 10:31:02

Message: 4 of 9

Thanks for your help.

However, the problem I now have is something like this:

1. I have a statement

if ~isdeployed

...do normal actions

else
try
a=which('file.xls')
xlswrite((fileparts(a),'\file.xls'),options)
end
end

I have realised the main problem is with the Which function.

Running the application via Matlab gives no problems. But
running the deployed function with which looks ONLY in the
CTF archive folder - as file.xls is not located there, the
application stops.

I know I can add MAT files to the archive, but XLS not.

There must be a way for the deployed application to find a
file anywhere on the path and provide the correct location
text?

Any ideas
Thanks
Matt




Bill August <hui.song@beds.ac.uk> wrote in message
<411948.1219058896499.JavaMail.jakarta@nitrogen.mathforum.or
g>...
> > Hi,
> >
> > I have an application (GUI) that also is compiled as
> > a
> > stand-alone executable to be run on other machines.
> >
> > 1. The GUI has some functions that require data to be
> >
> > saved/called from specific paths, e.g.
> > C:/Matlab7.1/work/Results
> >
> > 2. To ensure the data is stored in the correct
> > folders, I
> > use cd pathname, or xlswrite('pathname',data), for
> > example.
> >
> > 3. For some time, I was able to specify the pathname
> > as
> > only /Results, and this enabled flexibility - now I
> > get
> > error messages (unknown directory) and cannot trace
> > back
> > the problem - I now have to use the complete
> > pathname.
> >
> > 4. When I install the stand-alone executable on a new
> >
> > machine, the problem will occur that I do not have
> > the same
> > pathname as on the host computer, so when the script
> > cd or
> > xlswrite is executed with a specifie path, there will
> > be an
> > error.
> >
> > Can anyone think of a way to specify
> > folders/directories
> > that can be generic to any machine? e.g. a function
> > that
> > creates a folder "Results" in a common and sensible
> > location (i.e. the Program location f?r the
> > executable and
> > the work folder for the original -m files).
> >
> > Thanks
> > Matt
> Hi
> To me I always use the global variable.
> Add these code to the main function, and you can use the
relative path base on the root dir.
> global APP_ROOTDIR ;
> APP_ROOTDIR = which('APP_Start') ;
> CWIND_ROOTDIR = fileparts(APP_ROOTDIR) ;
> if isempty(APP_ROOTDIR)
> warning('Please change directory to the root, then
start it again.') ;
> return ;
> else
> end
>
>
> Message was edited by: Bill August
>

Subject: Matlab path issues

From: Bill August

Date: 20 Aug, 2008 12:56:32

Message: 5 of 9

> Thanks for your help.
>
> However, the problem I now have is something like
> this:
>
> 1. I have a statement
>
> if ~isdeployed
>
> ...do normal actions
>
> else
> try
> a=which('file.xls')
> xlswrite((fileparts(a),'\file.xls'),options)
> end
> end
>
> I have realised the main problem is with the Which
> function.
>
> Running the application via Matlab gives no problems.
> But
> running the deployed function with which looks ONLY
> in the
> CTF archive folder - as file.xls is not located
> there, the
> application stops.
>
> I know I can add MAT files to the archive, but XLS
> not.
>
> There must be a way for the deployed application to
> find a
> file anywhere on the path and provide the correct
> location
> text?
>
> Any ideas
> Thanks
> Matt
>
>
>
>
> Bill August <hui.song@beds.ac.uk> wrote in message
> <411948.1219058896499.JavaMail.jakarta@nitrogen.mathfo
> rum.or
> g>...
> > > Hi,
> > >
> > > I have an application (GUI) that also is compiled
> as
> > > a
> > > stand-alone executable to be run on other
> machines.
> > >
> > > 1. The GUI has some functions that require data
> to be
> > >
> > > saved/called from specific paths, e.g.
> > > C:/Matlab7.1/work/Results
> > >
> > > 2. To ensure the data is stored in the correct
> > > folders, I
> > > use cd pathname, or xlswrite('pathname',data),
> for
> > > example.
> > >
> > > 3. For some time, I was able to specify the
> pathname
> > > as
> > > only /Results, and this enabled flexibility - now
> I
> > > get
> > > error messages (unknown directory) and cannot
> trace
> > > back
> > > the problem - I now have to use the complete
> > > pathname.
> > >
> > > 4. When I install the stand-alone executable on a
> new
> > >
> > > machine, the problem will occur that I do not
> have
> > > the same
> > > pathname as on the host computer, so when the
> script
> > > cd or
> > > xlswrite is executed with a specifie path, there
> will
> > > be an
> > > error.
> > >
> > > Can anyone think of a way to specify
> > > folders/directories
> > > that can be generic to any machine? e.g. a
> function
> > > that
> > > creates a folder "Results" in a common and
> sensible
> > > location (i.e. the Program location f?r the
> > > executable and
> > > the work folder for the original -m files).
> > >
> > > Thanks
> > > Matt
> > Hi
> > To me I always use the global variable.
> > Add these code to the main function, and you can
> use the
> relative path base on the root dir.
> > global APP_ROOTDIR ;
> > APP_ROOTDIR = which('APP_Start') ;
> > CWIND_ROOTDIR = fileparts(APP_ROOTDIR) ;
> > if isempty(APP_ROOTDIR)
> > warning('Please change directory to the root,
> then
> start it again.') ;
> > return ;
> > else
> > end
> >
> >
> > Message was edited by: Bill August
> >
>
>
Hi Matthew,
Could you read my reply clearly?
I guess the file 'file.xls' has a fixed relative path to the deployed function (exe)?
If so, as long as you know the path (APP_PATH) of the deployed function (exe) then you can directly get the path of you xls file ([APP_PATH, relativepath]). And you DO NOT 'which' function any more...

Subject: Matlab path issues

From: Matthew Wade

Date: 20 Aug, 2008 13:16:01

Message: 6 of 9

Bill August <hui.song@beds.ac.uk> wrote in message
<16860251.1219237023270.JavaMail.jakarta@nitrogen.mathforum.
org>...
> > Thanks for your help.
> >
> > However, the problem I now have is something like
> > this:
> >
> > 1. I have a statement
> >
> > if ~isdeployed
> >
> > ...do normal actions
> >
> > else
> > try
> > a=which('file.xls')
> > xlswrite((fileparts(a),'\file.xls'),options)
> > end
> > end
> >
> > I have realised the main problem is with the Which
> > function.
> >
> > Running the application via Matlab gives no problems.
> > But
> > running the deployed function with which looks ONLY
> > in the
> > CTF archive folder - as file.xls is not located
> > there, the
> > application stops.
> >
> > I know I can add MAT files to the archive, but XLS
> > not.
> >
> > There must be a way for the deployed application to
> > find a
> > file anywhere on the path and provide the correct
> > location
> > text?
> >
> > Any ideas
> > Thanks
> > Matt
> >
> >
> >
> >
> > Bill August <hui.song@beds.ac.uk> wrote in message
> > <411948.1219058896499.JavaMail.jakarta@nitrogen.mathfo
> > rum.or
> > g>...
> > > > Hi,
> > > >
> > > > I have an application (GUI) that also is compiled
> > as
> > > > a
> > > > stand-alone executable to be run on other
> > machines.
> > > >
> > > > 1. The GUI has some functions that require data
> > to be
> > > >
> > > > saved/called from specific paths, e.g.
> > > > C:/Matlab7.1/work/Results
> > > >
> > > > 2. To ensure the data is stored in the correct
> > > > folders, I
> > > > use cd pathname, or xlswrite('pathname',data),
> > for
> > > > example.
> > > >
> > > > 3. For some time, I was able to specify the
> > pathname
> > > > as
> > > > only /Results, and this enabled flexibility - now
> > I
> > > > get
> > > > error messages (unknown directory) and cannot
> > trace
> > > > back
> > > > the problem - I now have to use the complete
> > > > pathname.
> > > >
> > > > 4. When I install the stand-alone executable on a
> > new
> > > >
> > > > machine, the problem will occur that I do not
> > have
> > > > the same
> > > > pathname as on the host computer, so when the
> > script
> > > > cd or
> > > > xlswrite is executed with a specifie path, there
> > will
> > > > be an
> > > > error.
> > > >
> > > > Can anyone think of a way to specify
> > > > folders/directories
> > > > that can be generic to any machine? e.g. a
> > function
> > > > that
> > > > creates a folder "Results" in a common and
> > sensible
> > > > location (i.e. the Program location f?r the
> > > > executable and
> > > > the work folder for the original -m files).
> > > >
> > > > Thanks
> > > > Matt
> > > Hi
> > > To me I always use the global variable.
> > > Add these code to the main function, and you can
> > use the
> > relative path base on the root dir.
> > > global APP_ROOTDIR ;
> > > APP_ROOTDIR = which('APP_Start') ;
> > > CWIND_ROOTDIR = fileparts(APP_ROOTDIR) ;
> > > if isempty(APP_ROOTDIR)
> > > warning('Please change directory to the root,
> > then
> > start it again.') ;
> > > return ;
> > > else
> > > end
> > >
> > >
> > > Message was edited by: Bill August
> > >
> >
> >
> Hi Matthew,
> Could you read my reply clearly?
> I guess the file 'file.xls' has a fixed relative path to
the deployed function (exe)?
> If so, as long as you know the path (APP_PATH) of the
deployed function (exe) then you can directly get the path
of you xls file ([APP_PATH, relativepath]). And you DO
NOT 'which' function any more...

Hi Bill,

Yes, I figured that one out.

Now I compile something like this:

mcc -m file.m -a file.xls

This works, but I am having a problem with some graphic
files. I have about 50 photographs in a folder called
Photos. These cannot be used (found on path) by deployed
function. So I tried:

mcc -m file.m -a file.xls -a C:/Programme.../Photos

Then executed the executable to create the CTF and looked
in the folder in the mcr folder (Photos) and its empty.

According to the help -a ./Folder, should add all files
located in that folder. Does not seem to work.

Cheers
Matt

Subject: Matlab path issues

From: Bill August

Date: 21 Aug, 2008 09:13:45

Message: 7 of 9

> Bill August <hui.song@beds.ac.uk> wrote in message
> <16860251.1219237023270.JavaMail.jakarta@nitrogen.math
> forum.
> org>...
> > > Thanks for your help.
> > >
> > > However, the problem I now have is something like
> > > this:
> > >
> > > 1. I have a statement
> > >
> > > if ~isdeployed
> > >
> > > ...do normal actions
> > >
> > > else
> > > try
> > > a=which('file.xls')
> > > xlswrite((fileparts(a),'\file.xls'),options)
> > > end
> > > end
> > >
> > > I have realised the main problem is with the
> Which
> > > function.
> > >
> > > Running the application via Matlab gives no
> problems.
> > > But
> > > running the deployed function with which looks
> ONLY
> > > in the
> > > CTF archive folder - as file.xls is not located
> > > there, the
> > > application stops.
> > >
> > > I know I can add MAT files to the archive, but
> XLS
> > > not.
> > >
> > > There must be a way for the deployed application
> to
> > > find a
> > > file anywhere on the path and provide the correct
> > > location
> > > text?
> > >
> > > Any ideas
> > > Thanks
> > > Matt
> > >
> > >
> > >
> > >
> > > Bill August <hui.song@beds.ac.uk> wrote in
> message
> > >
> <411948.1219058896499.JavaMail.jakarta@nitrogen.mathfo
> > > rum.or
> > > g>...
> > > > > Hi,
> > > > >
> > > > > I have an application (GUI) that also is
> compiled
> > > as
> > > > > a
> > > > > stand-alone executable to be run on other
> > > machines.
> > > > >
> > > > > 1. The GUI has some functions that require
> data
> > > to be
> > > > >
> > > > > saved/called from specific paths, e.g.
> > > > > C:/Matlab7.1/work/Results
> > > > >
> > > > > 2. To ensure the data is stored in the
> correct
> > > > > folders, I
> > > > > use cd pathname, or
> xlswrite('pathname',data),
> > > for
> > > > > example.
> > > > >
> > > > > 3. For some time, I was able to specify the
> > > pathname
> > > > > as
> > > > > only /Results, and this enabled flexibility -
> now
> > > I
> > > > > get
> > > > > error messages (unknown directory) and cannot
> > > trace
> > > > > back
> > > > > the problem - I now have to use the complete
> > > > > pathname.
> > > > >
> > > > > 4. When I install the stand-alone executable
> on a
> > > new
> > > > >
> > > > > machine, the problem will occur that I do not
> > > have
> > > > > the same
> > > > > pathname as on the host computer, so when the
> > > script
> > > > > cd or
> > > > > xlswrite is executed with a specifie path,
> there
> > > will
> > > > > be an
> > > > > error.
> > > > >
> > > > > Can anyone think of a way to specify
> > > > > folders/directories
> > > > > that can be generic to any machine? e.g. a
> > > function
> > > > > that
> > > > > creates a folder "Results" in a common and
> > > sensible
> > > > > location (i.e. the Program location f?r the
> > > > > executable and
> > > > > the work folder for the original -m files).
> > > > >
> > > > > Thanks
> > > > > Matt
> > > > Hi
> > > > To me I always use the global variable.
> > > > Add these code to the main function, and you
> can
> > > use the
> > > relative path base on the root dir.
> > > > global APP_ROOTDIR ;
> > > > APP_ROOTDIR = which('APP_Start') ;
> > > > CWIND_ROOTDIR = fileparts(APP_ROOTDIR) ;
> > > > if isempty(APP_ROOTDIR)
> > > > warning('Please change directory to the
> root,
> > > then
> > > start it again.') ;
> > > > return ;
> > > > else
> > > > end
> > > >
> > > >
> > > > Message was edited by: Bill August
> > > >
> > >
> > >
> > Hi Matthew,
> > Could you read my reply clearly?
> > I guess the file 'file.xls' has a fixed relative
> path to
> the deployed function (exe)?
> > If so, as long as you know the path (APP_PATH) of
> the
> deployed function (exe) then you can directly get the
> path
> of you xls file ([APP_PATH, relativepath]). And you
> DO
> NOT 'which' function any more...
>
> Hi Bill,
>
> Yes, I figured that one out.
>
> Now I compile something like this:
>
> mcc -m file.m -a file.xls
>
> This works, but I am having a problem with some
> graphic
> files. I have about 50 photographs in a folder called
>
> Photos. These cannot be used (found on path) by
> deployed
> function. So I tried:
>
> mcc -m file.m -a file.xls -a C:/Programme.../Photos
>
> Then executed the executable to create the CTF and
> looked
> in the folder in the mcr folder (Photos) and its
> empty.
>
> According to the help -a ./Folder, should add all
> files
> located in that folder. Does not seem to work.
>
> Cheers
> Matt
>
Hi Matt,
Depends on your requirment. If the data file is fixed, and you do not want to hide your files or not.
1. If you want to hide the files, you can use mcc ... -a \.path to add the whole folder to you achieve. Only one exe in your prject.
2. In any case, if you want to handle your folder visibly. I.e. output data. You can add a folder to the relative path the application. exe + files/folders.

Subject: Matlab path issues

From: Martin Rechsteiner

Date: 17 Apr, 2009 18:41:01

Message: 8 of 9

Bill August <hui.song@beds.ac.uk> wrote in message <10659078.1219310055957.JavaMail.jakarta@nitrogen.mathforum.org>...

May be this anwsers your question:

With the command 'pwd' you get the path to the directory where the application.exe resides.

Subject: Matlab path issues

From: Bruno Luong

Date: 17 Apr, 2009 18:54:01

Message: 9 of 9

For sometime I use a function similar to this to return the path of my application:

function pname=APP_path(varargin)

thisfile=mfilename('fullpath');
[pname] = fileparts(thisfile);
if isdeployed
    for upstep=1:2
        pos=find(pname==filesep, 1, 'last');
        pname=pname(1:pos-1);
    end
end

[pname] = strcat([pname filesep],varargin{:});

% Bruno

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
path pwd deploy... Martin Rechsteiner 17 Apr, 2009 14:45:07
location Matthew Wade 18 Aug, 2008 11:58:33
path Matthew Wade 18 Aug, 2008 11:58:33
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com