Thread Subject: Opening mat file in C

Subject: Opening mat file in C

From: Dhiman Saha

Date: 29 Jul, 2009 20:12:02

Message: 1 of 6

I want to open a mat file which has some two dimensional matrices in a C file. I followed the help file on that but when i compile the file i get lots of errors like "undefined reference to matOpen" and such errors for all the matlab functions. I have included the mat.h file in the include directory of the compiler. I am using the minGW compiler on windows XP.

IS there anything I need to include?

Thanks
Dhiman

Subject: Opening mat file in C

From: James Tursa

Date: 29 Jul, 2009 22:20:18

Message: 2 of 6

"Dhiman Saha" <saha.dhiman@gmail.com> wrote in message <h4qaei$10m$1@fred.mathworks.com>...
> I want to open a mat file which has some two dimensional matrices in a C file. I followed the help file on that but when i compile the file i get lots of errors like "undefined reference to matOpen" and such errors for all the matlab functions. I have included the mat.h file in the include directory of the compiler. I am using the minGW compiler on windows XP.
>
> IS there anything I need to include?
>
> Thanks
> Dhiman

Have you also included mex.h or engine.h? Can you show the source code you are trying?

James Tursa

Subject: Opening mat file in C

From: Dhiman Saha

Date: 30 Jul, 2009 01:08:01

Message: 3 of 6

"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <h4qhv1$t3$1@fred.mathworks.com>...
> "Dhiman Saha" <saha.dhiman@gmail.com> wrote in message <h4qaei$10m$1@fred.mathworks.com>...
> > I want to open a mat file which has some two dimensional matrices in a C file. I followed the help file on that but when i compile the file i get lots of errors like "undefined reference to matOpen" and such errors for all the matlab functions. I have included the mat.h file in the include directory of the compiler. I am using the minGW compiler on windows XP.
> >
> > IS there anything I need to include?
> >
> > Thanks
> > Dhiman
>
> Have you also included mex.h or engine.h? Can you show the source code you are trying?
>
> James Tursa

I just tried to compile the matdgns.c file given in matlab
edit([matlabroot '/extern/examples/eng_mat/matdgns.c']);
This file does not have any mex.h or engine.h included.


Dhiman

Subject: Opening mat file in C

From: James Tursa

Date: 30 Jul, 2009 07:38:00

Message: 4 of 6

"Dhiman Saha" <saha.dhiman@gmail.com> wrote in message <h4qrph$6o5$1@fred.mathworks.com>...
> "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <h4qhv1$t3$1@fred.mathworks.com>...
> > "Dhiman Saha" <saha.dhiman@gmail.com> wrote in message <h4qaei$10m$1@fred.mathworks.com>...
> > > I want to open a mat file which has some two dimensional matrices in a C file. I followed the help file on that but when i compile the file i get lots of errors like "undefined reference to matOpen" and such errors for all the matlab functions. I have included the mat.h file in the include directory of the compiler. I am using the minGW compiler on windows XP.
> > >
> > > IS there anything I need to include?
> > >
> > > Thanks
> > > Dhiman
> >
> > Have you also included mex.h or engine.h? Can you show the source code you are trying?
> >
> > James Tursa
>
> I just tried to compile the matdgns.c file given in matlab
> edit([matlabroot '/extern/examples/eng_mat/matdgns.c']);
> This file does not have any mex.h or engine.h included.
>

I just tried it and it compiled and ran fine. Here is what I did:

- Copied the file matdgns.c from the [matlabroot '/extern/examples/eng_mat'] directory to a work directory.

- Made that work directory the current directory

- Issued the following mex -setup command:

mex -setup
(then selected the MS VC 8.0 compiler)

- Issued the following commands (for MS VC 8.0):

options = [matlabroot '\bin\win32\mexopts\msvc80engmatopts.bat'];
mex('-f', options, 'matdgns.c', '-v');

- Ran the program with the following command:

!matdgns matlab.mat

James Tursa

Subject: Opening mat file in C

From: Dhiman Saha

Date: 30 Jul, 2009 12:04:01

Message: 5 of 6

"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <h4riko$h57$1@fred.mathworks.com>...
> "Dhiman Saha" <saha.dhiman@gmail.com> wrote in message <h4qrph$6o5$1@fred.mathworks.com>...
> > "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <h4qhv1$t3$1@fred.mathworks.com>...
> > > "Dhiman Saha" <saha.dhiman@gmail.com> wrote in message <h4qaei$10m$1@fred.mathworks.com>...
> > > > I want to open a mat file which has some two dimensional matrices in a C file. I followed the help file on that but when i compile the file i get lots of errors like "undefined reference to matOpen" and such errors for all the matlab functions. I have included the mat.h file in the include directory of the compiler. I am using the minGW compiler on windows XP.
> > > >
> > > > IS there anything I need to include?
> > > >
> > > > Thanks
> > > > Dhiman
> > >
> > > Have you also included mex.h or engine.h? Can you show the source code you are trying?
> > >
> > > James Tursa
> >
> > I just tried to compile the matdgns.c file given in matlab
> > edit([matlabroot '/extern/examples/eng_mat/matdgns.c']);
> > This file does not have any mex.h or engine.h included.
> >
>
> I just tried it and it compiled and ran fine. Here is what I did:
>
> - Copied the file matdgns.c from the [matlabroot '/extern/examples/eng_mat'] directory to a work directory.
>
> - Made that work directory the current directory
>
> - Issued the following mex -setup command:
>
> mex -setup
> (then selected the MS VC 8.0 compiler)
>
> - Issued the following commands (for MS VC 8.0):
>
> options = [matlabroot '\bin\win32\mexopts\msvc80engmatopts.bat'];
> mex('-f', options, 'matdgns.c', '-v');
>
> - Ran the program with the following command:
>
> !matdgns matlab.mat
>
> James Tursa


Thank you for the reply. But can i use matdgns.c file on the MinGW compiler. Also how can i open the mat file using C in a system that does not have matlab installed. (If its required I can also post this as a new problem.)

Dhiman Saha

Subject: Opening mat file in C

From: Ashish Uthama

Date: 30 Jul, 2009 12:58:09

Message: 6 of 6

On Thu, 30 Jul 2009 08:04:01 -0400, Dhiman Saha <saha.dhiman@gmail.com>
wrote:

> "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message
> <h4riko$h57$1@fred.mathworks.com>...
>> "Dhiman Saha" <saha.dhiman@gmail.com> wrote in message
>> <h4qrph$6o5$1@fred.mathworks.com>...
>> > "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message
>> <h4qhv1$t3$1@fred.mathworks.com>...
>> > > "Dhiman Saha" <saha.dhiman@gmail.com> wrote in message
>> <h4qaei$10m$1@fred.mathworks.com>...
>> > > > I want to open a mat file which has some two dimensional matrices
>> in a C file. I followed the help file on that but when i compile the
>> file i get lots of errors like "undefined reference to matOpen" and
>> such errors for all the matlab functions. I have included the mat.h
>> file in the include directory of the compiler. I am using the minGW
>> compiler on windows XP.
>> > > >
>> > > > IS there anything I need to include?
>> > > >
>> > > > Thanks
>> > > > Dhiman
>> > >
>> > > Have you also included mex.h or engine.h? Can you show the source
>> code you are trying?
>> > >
>> > > James Tursa
>> >
>> > I just tried to compile the matdgns.c file given in matlab
>> > edit([matlabroot '/extern/examples/eng_mat/matdgns.c']);
>> > This file does not have any mex.h or engine.h included.
>> >
>>
>> I just tried it and it compiled and ran fine. Here is what I did:
>>
>> - Copied the file matdgns.c from the [matlabroot
>> '/extern/examples/eng_mat'] directory to a work directory.
>>
>> - Made that work directory the current directory
>>
>> - Issued the following mex -setup command:
>>
>> mex -setup
>> (then selected the MS VC 8.0 compiler)
>>
>> - Issued the following commands (for MS VC 8.0):
>>
>> options = [matlabroot '\bin\win32\mexopts\msvc80engmatopts.bat'];
>> mex('-f', options, 'matdgns.c', '-v');
>>
>> - Ran the program with the following command:
>>
>> !matdgns matlab.mat
>>
>> James Tursa
>
>
> Thank you for the reply. But can i use matdgns.c file on the MinGW
> compiler. Also how can i open the mat file using C in a system that does
> not have matlab installed. (If its required I can also post this as a
> new problem.)
>
> Dhiman Saha


Dhiman,

I would first try out what James suggested to ensure that the documented
workflow runs cleanly. I would then start out customizing it for my
workflow.

Did you have a chance to peruse this document?
     http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f30937.html
Or please paste this in the MATLAB command window:
     web([docroot,'/techdoc/matlab_external/f30937.html'])

Specially this section which talks about compilation and deployment to
systems without MATLAB.

Please find more details online at:
     http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f19027.html
Or please paste this in the MATLAB command window:
     web([docroot,'/techdoc/matlab_external/f19027.html'])


Another trick is to use the -v option with the mex command to figure out
the actual command line args sent to the compiler. You could use this
information to then configure your compiler outside MATLAB to pass the
required settings/libraries/include files.

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
mat files Dhiman Saha 29 Jul, 2009 16:39:32
c and matlab Dhiman Saha 29 Jul, 2009 16:14:01
c Dhiman Saha 29 Jul, 2009 16:14:01
rssFeed for this Thread
 

MATLAB Central Terms of Use

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 Terms prior to use.

Contact us at files@mathworks.com