Thread Subject: How does the MATLAB Compiler deal with .mat files?

Subject: How does the MATLAB Compiler deal with .mat files?

From: William

Date: 26 Jun, 2009 21:49:01

Message: 1 of 9

I am trying to create an executable file using the MATLAB compiler. I am creating a GUI that uses a .mat file for loading data every time it is opened, but the .mat file is not being integrated into the executable files. Without it, my GUI throws an error.

The command for compiling MATLAB files into an executable is:

mcc -m stuff.m moreStuff.m evenMoreStuff.m

I have tried to add the .mat file to the list (after -m), but it doesn't seem to work properly. how does the MATLAB compiler deal with .mat files and have can I add them for the .exe to use?

Thank you,
Billy

Subject: How does the MATLAB Compiler deal with .mat files?

From: Bruno Luong

Date: 26 Jun, 2009 23:02:03

Message: 2 of 9

"William" <w_king10@yahoo.com> wrote in message <h23fod$8p2$1@fred.mathworks.com>...
> I am trying to create an executable file using the MATLAB compiler. I am creating a GUI that uses a .mat file for loading data every time it is opened, but the .mat file is not being integrated into the executable files. Without it, my GUI throws an error.
>
> The command for compiling MATLAB files into an executable is:
>
> mcc -m stuff.m moreStuff.m evenMoreStuff.m
>
> I have tried to add the .mat file to the list (after -m), but it doesn't seem to work properly. how does the MATLAB compiler deal with .mat files and have can I add them for the .exe to use?

Why you should add them in the EXE file? Any data files should keep separately. They will be used as normal.

Bruno

Subject: How does the MATLAB Compiler deal with .mat files?

From: William

Date: 28 Jul, 2009 02:09:02

Message: 3 of 9

I guess I don't really understand how to leave it seperately. The MAT file is used by the program everytime the application is launched. It contains parameters that the program needs. I am looking to create an executable with everything required, so I can send the whole thing to people who will use the program. Keeping the MAT files separate, will just be confusing for the end user.

How can I integrate needed MAT files in with an exe when it is created using the Matlab compiler. Has anyone been able to do this yet?

Subject: How does the MATLAB Compiler deal with .mat files?

From: Bruno Luong

Date: 28 Jul, 2009 05:57:01

Message: 4 of 9

"William" <w_king10@yahoo.com> wrote in message <h4lmjt$4mh$1@fred.mathworks.com>...
> I guess I don't really understand how to leave it seperately. The MAT file is used by the program everytime the application is launched. It contains parameters that the program needs. I am looking to create an executable with everything required, so I can send the whole thing to people who will use the program. Keeping the MAT files separate, will just be confusing for the end user.
>
> How can I integrate needed MAT files in with an exe when it is created using the Matlab compiler. Has anyone been able to do this yet?

Pack your files with an application installer (such as NSIS http://nsis.sourceforge.net/Main_Page). This is not the job of the compiler.

Bruno

Subject: How does the MATLAB Compiler deal with .mat files?

From: William

Date: 29 Jul, 2009 00:22:02

Message: 5 of 9

OK...that makes no sense to me either. I will have to tell the installer where to put the .mat file. Correct? Therefore, when I use the mcc command to create the executable, I should then be able to put the required .mat file somewhere manually without using the installer. Correct? Where do I put it? In which folder?

I have not found the appropriate location and cannot find documentation in MATLAB for dealing with .mat files in executables. NSIS, as far as I know, isn't designed to work specifically with MATLAB files. Therefore, it won't know what to do with the file I am having trouble with.

I appreciate your help, but pointing me in the direction of random programs without specific instructions on where to put things is not helping me solve my original problem...getting my compiled application to work. The .mat file in my program is a file that is used every time my program launches and every time it closes. It holds the configuration values that are saved upon closing and loaded upon launching. My application looks for that file in a specific place. However, no matter where I put it, the application doesn't recognize it once compiled. Is there something I'm missing?

Thanks,
Billy

Subject: How does the MATLAB Compiler deal with .mat files?

From: TideMan

Date: 29 Jul, 2009 02:10:03

Message: 6 of 9

On Jul 29, 12:22 pm, "William" <w_kin...@yahoo.com> wrote:
> OK...that makes no sense to me either.  I will have to tell the installer where to put the .mat file.  Correct?  Therefore, when I use the mcc command to create the executable, I should then be able to put the required .mat file somewhere manually without using the installer.  Correct?  Where do I put it?  In which folder?  
>
> I have not found the appropriate location and cannot find documentation in MATLAB for dealing with .mat files in executables.  NSIS, as far as I know, isn't designed to work specifically with MATLAB files.  Therefore, it won't know what to do with the file I am having trouble with.  
>
> I appreciate your help, but pointing me in the direction of random programs without specific instructions on where to put things is not helping me solve my original problem...getting my compiled application to work.  The .mat file in my program is a file that is used every time my program launches and every time it closes.  It holds the configuration values that are saved upon closing and loaded upon launching.  My application looks for that file in a specific place.  However, no matter where I put it, the application doesn't recognize it once compiled.  Is there something I'm missing?
>
> Thanks,
> Billy

Yes, you are missing something: the sense to listen to the good advice
that Bruno has given you.

When you run your program on your own machine, where does the .mat
file sit?
Then that is exactly where it should sit when you run it on your
users' machines, be that the current directory or somewhere else.
I would write a ReadMe to explain how the program must be installed,
then zip it up along with the .exe and .mat files using WinRAR or
similar. Most users can handle that.

Subject: How does the MATLAB Compiler deal with .mat files?

From: ImageAnalyst

Date: 29 Jul, 2009 02:50:01

Message: 7 of 9

On Jul 28, 8:22 pm, "William" <w_kin...@yahoo.com> wrote:
> OK...that makes no sense to me either.  I will have to tell the installer where to put the .mat file.  Correct?  Therefore, when I use the mcc command to create the executable, I should then be able to put the required .mat file somewhere manually without using the installer.  Correct?  Where do I put it?  In which folder?  
>
> I have not found the appropriate location and ...
[snip].  

> Thanks,
> Billy

Billy:
You should probably put the mat file in the same folder as your
executable. The trick is that unless you put a "cd somepath" in your
startup.m file when you compile it, it will most likely startup with
"my documents\MATLAB" as the current folder when you run your
executable and if you don't put the full path of your mat file, then
it will look there, which is most likely NOT where you installed your
executable in. I suggest you play around with this code (the ShowPath
() function). Also, look at the url (in the comment section) for a
discussion Bruno and others had to help explain it to you (it was
basically the same question you're having)

% Returns the path of the executable.
% http://groups.google.com/group/comp.soft-sys.matlab/browse_frm/thread/b326963a69020d8b/55ac59a943d
% ac841?hl=en&lnk=gst&q=current+directory+exe#55ac59a943dac841
% My test program gives the following output:
% pwd: C:\WINDOWS
% AppRootPath: C:\DOCUME~1\username\LOCALS~1\Temp\username
\mcrCache7.10\
% userpath: C:\Documents and Settings\username\My Documents\MATLAB;
% showpath: D:\Projects\testPath
%
%
% The test program was
% function testPath()
% % mcc -mv testPath
% disp(['pwd: ' pwd]);
% disp(['AppRootPath: ' AppRootPath()])
% disp(['userpath: ' userpath])
% disp(['showpath: ' showpath()]);
% input('Press return');
% end
function [thePath] = ShowPath()
% Show EXE path:
if isdeployed % Stand-alone mode.
[status, result] = system('set PATH');
thePath = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
else % Running from MATLAB.
[macroFolder, baseFileName, ext] = fileparts(mfilename('fullpath'));
thePath = macroFolder;
% thePath = pwd;
end
return ;

William:
Use the above code to construct the full path of your mat file, which
(like I said) I'd recommend putting in the same folder as your
executable. It works for me. But after that, you'll still have to
distribute your mat file with your executable and any other run-time
files that are needed that can't be built into the executable, such as
documentation, help files, sample data files, splash images, etc. I
use the Wise installer to bundle all these up into a single
installation file, but you can use whatever installation package you
want.
Good luck,
ImageAnalyst

Subject: How does the MATLAB Compiler deal with .mat files?

From: William

Date: 3 Aug, 2009 23:57:03

Message: 8 of 9

Thanks for the reply. I will try this tonight when I get to the lab. I understand what you are saying and appreciate what Bruno was trying to tell me. I just get frustrated when I get one word answers with no real explanation. Hopefully, setting the path will fix my problem.

Billy

Subject: How does the MATLAB Compiler deal with .mat files?

From: Mario

Date: 24 May, 2011 13:47:05

Message: 9 of 9

William,
I had a similar problem: If there is no configuration file at present, the executable shall create one. The task was to store the configuration file in the executable. My solution is the following:

- Open the configuration file that has to be stored in the executable with a hex editor. For this you can Hex Workshop v3.11 which is Freeware.

- Copy the hex numbers into your matlab code and create the configuration file by using hex2dec.


Example:

- The configuration file is a m-file config.m contains:
variable1 = [1:4 9];
string1 = 'Hello world';

- The corresponding hex numbers are:
7661726961626C6531203D205B313A3420395D3B0D0A737472696E6731203D202748656C6C6F20776F726C64273B

- Then the code can look like the following one:
filename = 'config.m';
fid = fopen(filename,'r'); % open configuration file
if isequal(fid,-1)
  fid = fopen(filename,'w+'); % create new file for reading and writing
  if isequal(fid,-1)
    disp('Loading of configuration file skipped. New file could not be created.')
  else
    disp('String', 'Loading of configuration file skipped. New file has been created.')
    A = '7661726961626C6531203D205B313A3420395D3B0D0A737472696E6731203D202748656C6C6F20776F726C64273B';
    L = length(A); % length of hex string = number of hex numbers
    n = 2; % 2 hex numbers form 1 Byte or 8 Bit resp.
    N = floor(L/n); % number of Bytes
    K = (0:n-1:L-N-n+1)'; % used to form index matrix I
    I = hankel(1:N,N:N+n-1) + K(:,ones(n, 1)); % index matrix
    fwrite(fid, hex2dec(A(I)), 'uint8', 0, 'b'); % create configuration file
    fseek(fid, 0, 'bof'); % return to beginning of file
  end
else
  disp('Configuration file applied.')
end
if ~isequal(fid,-1)
  cmdStringMatrix = fscanf(fid, '%c'); % read whole text from configuration file
  fclose(fid); % close file
...

Mario

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
create file by ... Mario 24 May, 2011 09:49:10
include file in... Mario 24 May, 2011 09:49:10
nsis Sprinceana 28 Jul, 2009 03:00:42
mcc William 27 Jul, 2009 22:14:06
exe William 27 Jul, 2009 22:14:06
superman William 26 Jun, 2009 17:54:02
compiler William 26 Jun, 2009 17:54:02
c William 26 Jun, 2009 17:54:02
mat William 26 Jun, 2009 17:54:02
m William 26 Jun, 2009 17:54:02
gui William 26 Jun, 2009 17:54:01
rssFeed for this Thread

Contact us at files@mathworks.com