<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254796</link>
    <title>MATLAB Central Newsreader - How does the MATLAB Compiler deal with .mat files?</title>
    <description>Feed for thread: How does the MATLAB Compiler deal with .mat files?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 26 Jun 2009 21:49:01 -0400</pubDate>
      <title>How does the MATLAB Compiler deal with .mat files?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254796#660837</link>
      <author>William </author>
      <description>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.  &lt;br&gt;
&lt;br&gt;
The command for compiling MATLAB files into an executable is:&lt;br&gt;
&lt;br&gt;
mcc -m stuff.m moreStuff.m evenMoreStuff.m&lt;br&gt;
&lt;br&gt;
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?&lt;br&gt;
&lt;br&gt;
Thank you,&lt;br&gt;
Billy</description>
    </item>
    <item>
      <pubDate>Fri, 26 Jun 2009 23:02:03 -0400</pubDate>
      <title>Re: How does the MATLAB Compiler deal with .mat files?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254796#660846</link>
      <author>Bruno Luong</author>
      <description>&quot;William&quot; &amp;lt;w_king10@yahoo.com&amp;gt; wrote in message &amp;lt;h23fod$8p2$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; 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.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The command for compiling MATLAB files into an executable is:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; mcc -m stuff.m moreStuff.m evenMoreStuff.m&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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?&lt;br&gt;
&lt;br&gt;
Why you should add them in the EXE file? Any data files should keep separately. They will be used as normal.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Tue, 28 Jul 2009 02:09:02 -0400</pubDate>
      <title>Re: How does the MATLAB Compiler deal with .mat files?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254796#668627</link>
      <author>William </author>
      <description>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.  &lt;br&gt;
&lt;br&gt;
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?</description>
    </item>
    <item>
      <pubDate>Tue, 28 Jul 2009 05:57:01 -0400</pubDate>
      <title>Re: How does the MATLAB Compiler deal with .mat files?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254796#668642</link>
      <author>Bruno Luong</author>
      <description>&quot;William&quot; &amp;lt;w_king10@yahoo.com&amp;gt; wrote in message &amp;lt;h4lmjt$4mh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; 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.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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?&lt;br&gt;
&lt;br&gt;
Pack your files with an application installer (such as NSIS &lt;a href=&quot;http://nsis.sourceforge.net/Main_Page).&quot;&gt;http://nsis.sourceforge.net/Main_Page).&lt;/a&gt; This is not the job of the compiler.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Wed, 29 Jul 2009 00:22:02 -0400</pubDate>
      <title>Re: How does the MATLAB Compiler deal with .mat files?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254796#668965</link>
      <author>William </author>
      <description>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?  &lt;br&gt;
&lt;br&gt;
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.  &lt;br&gt;
&lt;br&gt;
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?&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
Billy</description>
    </item>
    <item>
      <pubDate>Wed, 29 Jul 2009 02:10:03 -0400</pubDate>
      <title>Re: How does the MATLAB Compiler deal with .mat files?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254796#668971</link>
      <author>TideMan</author>
      <description>On Jul 29, 12:22&#160;pm, &quot;William&quot; &amp;lt;w_kin...@yahoo.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; OK...that makes no sense to me either. &#160;I will have to tell the installer where to put the .mat file. &#160;Correct? &#160;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. &#160;Correct? &#160;Where do I put it? &#160;In which folder? &#160;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have not found the appropriate location and cannot find documentation in MATLAB for dealing with .mat files in executables. &#160;NSIS, as far as I know, isn't designed to work specifically with MATLAB files. &#160;Therefore, it won't know what to do with the file I am having trouble with. &#160;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; 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. &#160;The .mat file in my program is a file that is used every time my program launches and every time it closes. &#160;It holds the configuration values that are saved upon closing and loaded upon launching. &#160;My application looks for that file in a specific place. &#160;However, no matter where I put it, the application doesn't recognize it once compiled. &#160;Is there something I'm missing?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; Billy&lt;br&gt;
&lt;br&gt;
Yes, you are missing something: the sense to listen to the good advice&lt;br&gt;
that Bruno has given you.&lt;br&gt;
&lt;br&gt;
When you run your program on your own machine, where does the .mat&lt;br&gt;
file sit?&lt;br&gt;
Then that is exactly where it should sit when you run it on your&lt;br&gt;
users' machines, be that the current directory or somewhere else.&lt;br&gt;
I would write a ReadMe to explain how the program must be installed,&lt;br&gt;
then zip it up along with the .exe and .mat files using WinRAR or&lt;br&gt;
similar.  Most users can handle that.</description>
    </item>
    <item>
      <pubDate>Wed, 29 Jul 2009 02:50:01 -0400</pubDate>
      <title>Re: How does the MATLAB Compiler deal with .mat files?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254796#668979</link>
      <author>ImageAnalyst</author>
      <description>On Jul 28, 8:22&#160;pm, &quot;William&quot; &amp;lt;w_kin...@yahoo.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; OK...that makes no sense to me either. &#160;I will have to tell the installer where to put the .mat file. &#160;Correct? &#160;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. &#160;Correct? &#160;Where do I put it? &#160;In which folder? &#160;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have not found the appropriate location and ...&lt;br&gt;
[snip]. &#160;&lt;br&gt;
&lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; Billy&lt;br&gt;
&lt;br&gt;
Billy:&lt;br&gt;
You should probably put the mat file in the same folder as your&lt;br&gt;
executable.  The trick is that unless you put a &quot;cd somepath&quot; in your&lt;br&gt;
startup.m file when you compile it, it will most likely startup with&lt;br&gt;
&quot;my documents\MATLAB&quot; as the current folder when you run your&lt;br&gt;
executable and if you don't put the full path of your mat file, then&lt;br&gt;
it will look there, which is most likely NOT where you installed your&lt;br&gt;
executable in.  I suggest you play around with this code (the ShowPath&lt;br&gt;
() function).  Also, look at the url (in the comment section) for a&lt;br&gt;
discussion Bruno and others had to help explain it to you (it was&lt;br&gt;
basically the same question you're having)&lt;br&gt;
&lt;br&gt;
% Returns the path of the executable.&lt;br&gt;
% &lt;a href=&quot;http://groups.google.com/group/comp.soft-sys.matlab/browse_frm/thread/b326963a69020d8b/55ac59a943d&quot;&gt;http://groups.google.com/group/comp.soft-sys.matlab/browse_frm/thread/b326963a69020d8b/55ac59a943d&lt;/a&gt;&lt;br&gt;
% ac841?hl=en&amp;lnk=gst&amp;q=current+directory+exe#55ac59a943dac841&lt;br&gt;
% My test program gives the following output:&lt;br&gt;
% pwd: C:\WINDOWS&lt;br&gt;
% AppRootPath: C:\DOCUME~1\username\LOCALS~1\Temp\username&lt;br&gt;
\mcrCache7.10\&lt;br&gt;
% userpath: C:\Documents and Settings\username\My Documents\MATLAB;&lt;br&gt;
% showpath: D:\Projects\testPath&lt;br&gt;
%&lt;br&gt;
%&lt;br&gt;
% The test program was&lt;br&gt;
% function testPath()&lt;br&gt;
% % mcc -mv testPath&lt;br&gt;
% disp(['pwd: ' pwd]);&lt;br&gt;
% disp(['AppRootPath: ' AppRootPath()])&lt;br&gt;
% disp(['userpath: ' userpath])&lt;br&gt;
% disp(['showpath: ' showpath()]);&lt;br&gt;
% input('Press return');&lt;br&gt;
% end&lt;br&gt;
function [thePath] = ShowPath()&lt;br&gt;
	% Show EXE path:&lt;br&gt;
	if isdeployed % Stand-alone mode.&lt;br&gt;
		[status, result] = system('set PATH');&lt;br&gt;
		thePath = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));&lt;br&gt;
	else % Running from MATLAB.&lt;br&gt;
		[macroFolder, baseFileName, ext] = fileparts(mfilename('fullpath'));&lt;br&gt;
		thePath = macroFolder;&lt;br&gt;
% 		thePath = pwd;&lt;br&gt;
	end&lt;br&gt;
	return ;&lt;br&gt;
&lt;br&gt;
William:&lt;br&gt;
Use the above code to construct the full path of your mat file, which&lt;br&gt;
(like I said) I'd recommend putting in the same folder as your&lt;br&gt;
executable.  It works for me.  But after that, you'll still have to&lt;br&gt;
distribute your mat file with your executable and any other run-time&lt;br&gt;
files that are needed that can't be built into the executable, such as&lt;br&gt;
documentation, help files, sample data files, splash images, etc.  I&lt;br&gt;
use the Wise installer to bundle all these up into a single&lt;br&gt;
installation file, but you can use whatever installation package you&lt;br&gt;
want.&lt;br&gt;
Good luck,&lt;br&gt;
ImageAnalyst</description>
    </item>
    <item>
      <pubDate>Mon, 03 Aug 2009 23:57:03 -0400</pubDate>
      <title>Re: How does the MATLAB Compiler deal with .mat files?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254796#670398</link>
      <author>William </author>
      <description>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.  &lt;br&gt;
&lt;br&gt;
Billy</description>
    </item>
    <item>
      <pubDate>Tue, 24 May 2011 13:47:05 -0400</pubDate>
      <title>Re: How does the MATLAB Compiler deal with .mat files?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/254796#837669</link>
      <author>Mario </author>
      <description>William,&lt;br&gt;
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:&lt;br&gt;
&lt;br&gt;
- 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.&lt;br&gt;
&lt;br&gt;
- Copy the hex numbers into your matlab code and create the configuration file by using hex2dec.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Example:&lt;br&gt;
&lt;br&gt;
- The configuration file is a m-file config.m contains:&lt;br&gt;
variable1 = [1:4 9];&lt;br&gt;
string1 = 'Hello world';&lt;br&gt;
&lt;br&gt;
- The corresponding hex numbers are:&lt;br&gt;
7661726961626C6531203D205B313A3420395D3B0D0A737472696E6731203D202748656C6C6F20776F726C64273B&lt;br&gt;
&lt;br&gt;
- Then the code can look like the following one:&lt;br&gt;
filename = 'config.m';&lt;br&gt;
fid = fopen(filename,'r'); % open configuration file&lt;br&gt;
if isequal(fid,-1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;fid = fopen(filename,'w+'); % create new file for reading and writing&lt;br&gt;
&amp;nbsp;&amp;nbsp;if isequal(fid,-1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp('Loading of configuration file skipped. New file could not be created.')&lt;br&gt;
&amp;nbsp;&amp;nbsp;else&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp('String', 'Loading of configuration file skipped. New file has been created.')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;A = '7661726961626C6531203D205B313A3420395D3B0D0A737472696E6731203D202748656C6C6F20776F726C64273B';&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;L = length(A); % length of hex string = number of hex numbers&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;n = 2; % 2 hex numbers form 1 Byte or 8 Bit resp.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;N = floor(L/n); % number of Bytes&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;K = (0:n-1:L-N-n+1)'; % used to form index matrix I&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;I = hankel(1:N,N:N+n-1) + K(:,ones(n, 1)); % index matrix&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fwrite(fid, hex2dec(A(I)), 'uint8', 0, 'b');    % create configuration file&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fseek(fid, 0, 'bof'); % return to beginning of file&lt;br&gt;
&amp;nbsp;&amp;nbsp;end&lt;br&gt;
else&lt;br&gt;
&amp;nbsp;&amp;nbsp;disp('Configuration file applied.')&lt;br&gt;
end&lt;br&gt;
if ~isequal(fid,-1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;cmdStringMatrix = fscanf(fid, '%c'); % read whole text from configuration file&lt;br&gt;
&amp;nbsp;&amp;nbsp;fclose(fid); % close file&lt;br&gt;
...&lt;br&gt;
&lt;br&gt;
Mario</description>
    </item>
  </channel>
</rss>

