Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Export Data from C to MATLAB

Subject: Export Data from C to MATLAB

From: Jeff

Date: 29 Oct, 2012 02:21:08

Message: 1 of 10

Someone please point me to the MAT-file interface and documentation.

I am trying to find the best way to export large amounts of long float data from C on a parallel cluster for use in Matlab (http://bit.ly/QPp4CI). I was referred to this thread (http://bit.ly/RfJu87), which wasn't any help but which referenced this document (http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/matfile_format.pdf) about the MAT-File formath, whcih implied there is a C library called the "Mat-file interface" which could do what I want.

I searched mathworks for "MAT-file interface", but did not receive any promising looking links (I investigated the first few links anyway, so I promise I tried to look!)

Two fold question:
1) Where is the MAT-file interface and documentation?
2) What is the best way to export boatloads of data from C into Matlab (the data is being generated a little at a time by an ODE solver).

Thank you.

Subject: Export Data from C to MATLAB

From: Steven_Lord

Date: 29 Oct, 2012 03:15:54

Message: 2 of 10



"Jeff " <spREMOVEHITSjeffAT@SIGNoptonline.net> wrote in message
news:k6kp6j$o2o$1@newscl01ah.mathworks.com...
> Someone please point me to the MAT-file interface and documentation.
>
> I am trying to find the best way to export large amounts of long float
> data from C on a parallel cluster for use in Matlab
> (http://bit.ly/QPp4CI). I was referred to this thread
> (http://bit.ly/RfJu87), which wasn't any help but which referenced this
> document
> (http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/matfile_format.pdf)
> about the MAT-File formath, whcih implied there is a C library called the
> "Mat-file interface" which could do what I want.
>
> I searched mathworks for "MAT-file interface", but did not receive any
> promising looking links (I investigated the first few links anyway, so I
> promise I tried to look!)
>
> Two fold question:
> 1) Where is the MAT-file interface and documentation?

http://www.mathworks.com/help/matlab/read-and-write-matlab-mat-files-in-c-c-and-fortran.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Export Data from C to MATLAB

From: Jeff

Date: 31 Oct, 2012 21:03:08

Message: 3 of 10

"Steven_Lord" <slord@mathworks.com> wrote in message <k6ksda$575$1@newscl01ah.mathworks.com>...
>
>
> "Jeff " <spREMOVEHITSjeffAT@SIGNoptonline.net> wrote in message
> news:k6kp6j$o2o$1@newscl01ah.mathworks.com...
> > Someone please point me to the MAT-file interface and documentation.
> >
> > I am trying to find the best way to export large amounts of long float
> > data from C on a parallel cluster for use in Matlab
> > (http://bit.ly/QPp4CI). I was referred to this thread
> > (http://bit.ly/RfJu87), which wasn't any help but which referenced this
> > document
> > (http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/matfile_format.pdf)
> > about the MAT-File formath, whcih implied there is a C library called the
> > "Mat-file interface" which could do what I want.
> >
> > I searched mathworks for "MAT-file interface", but did not receive any
> > promising looking links (I investigated the first few links anyway, so I
> > promise I tried to look!)
> >
> > Two fold question:
> > 1) Where is the MAT-file interface and documentation?
>
> http://www.mathworks.com/help/matlab/read-and-write-matlab-mat-files-in-c-c-and-fortran.html
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Thanks. That will help (obviously!).
As a followup question, what is the best way to export data from a C program on Linux (on a system which does not have MATLAB on it) to be used in MATLAB?

Subject: Export Data from C to MATLAB

From: Jeff

Date: 31 Oct, 2012 21:14:08

Message: 4 of 10

As a followup question, what is the best way to export data from a C program on Linux (on a system which does not have MATLAB on it) to be used in MATLAB?

Just to add some detail: my advisor thinks I should just printf the data. But there is a lot of data, might this be too much for MATLAB to accept in a text file? Is there a better way?

Thanks.

Subject: Export Data from C to MATLAB

From: James Tursa

Date: 31 Oct, 2012 21:23:09

Message: 5 of 10

"Jeff" wrote in message <k6s4b0$hbd$1@newscl01ah.mathworks.com>...
> As a followup question, what is the best way to export data from a C program on Linux (on a system which does not have MATLAB on it) to be used in MATLAB?
>
> Just to add some detail: my advisor thinks I should just printf the data. But there is a lot of data, might this be too much for MATLAB to accept in a text file? Is there a better way?
>
> Thanks.

Best way typically is to simply write the data out to a binary file and then use fopen/fread on the MATLAB side to read it in. Takes less time, less storage, and avoids roundoff differences when compared to a text file approach via printf.

James Tursa

Subject: Export Data from C to MATLAB

From: dpb

Date: 31 Oct, 2012 21:26:07

Message: 6 of 10

On 10/31/2012 4:14 PM, Jeff wrote:
> As a followup question, what is the best way to export data from a C
> program on Linux (on a system which does not have MATLAB on it) to be
> used in MATLAB?
>
> Just to add some detail: my advisor thinks I should just printf the
> data. But there is a lot of data, might this be too much for MATLAB to
> accept in a text file? Is there a better way?

I'd suggest stream unformatted as much better since it will be full
precision and assuming the data is double quite a lot smaller of a file.

Matlab has great flexibility in fread combined w/ fopen to handle any
common format currently in use.

--

Subject: Export Data from C to MATLAB

From: dpb

Date: 31 Oct, 2012 21:29:28

Message: 7 of 10

On 10/31/2012 4:26 PM, dpb wrote:
...

> I'd suggest stream unformatted as much better since it will be full
> precision and assuming the data is double quite a lot smaller of a file.
>
...

That would be fwrite(), of course...

--

Subject: Export Data from C to MATLAB

From: Jeff

Date: 31 Oct, 2012 23:06:08

Message: 8 of 10

"James Tursa" wrote in message <k6s4rt$j6t$1@newscl01ah.mathworks.com>...
> "Jeff" wrote in message <k6s4b0$hbd$1@newscl01ah.mathworks.com>...
> > As a followup question, what is the best way to export data from a C program on Linux (on a system which does not have MATLAB on it) to be used in MATLAB?
> >
> > Just to add some detail: my advisor thinks I should just printf the data. But there is a lot of data, might this be too much for MATLAB to accept in a text file? Is there a better way?
> >
> > Thanks.
>
> Best way typically is to simply write the data out to a binary file and then use fopen/fread on the MATLAB side to read it in. Takes less time, less storage, and avoids roundoff differences when compared to a text file approach via printf.
>
> James Tursa

Thanks, James. Since you're speaking to a C and MATLAB newbie, could you provide a line or two of code to clarify "write data out to a binary file"?

Subject: Export Data from C to MATLAB

From: Jeff

Date: 31 Oct, 2012 23:10:11

Message: 9 of 10

dpb <none@non.net> wrote in message <k6s4vn$pll$1@speranza.aioe.org>...
> On 10/31/2012 4:14 PM, Jeff wrote:
> > As a followup question, what is the best way to export data from a C
> > program on Linux (on a system which does not have MATLAB on it) to be
> > used in MATLAB?
> >
> > Just to add some detail: my advisor thinks I should just printf the
> > data. But there is a lot of data, might this be too much for MATLAB to
> > accept in a text file? Is there a better way?
>
> I'd suggest stream unformatted as much better since it will be full
> precision and assuming the data is double quite a lot smaller of a file.
>
> Matlab has great flexibility in fread combined w/ fopen to handle any
> common format currently in use.
>
> --

Hi dpb. Thanks. Could you clarify "stream unformatted" to a C and MATLAB newbie (that's me)? A line or two of code which shows what you mean is best, because then I can just read about the commands you show. Do you mean "fwrite" in C or in MATLAB?

Subject: Export Data from C to MATLAB

From: dpb

Date: 1 Nov, 2012 01:22:51

Message: 10 of 10

On 10/31/2012 6:10 PM, Jeff wrote:
> dpb <none@non.net> wrote in message <k6s4vn$pll$1@speranza.aioe.org>...
>> On 10/31/2012 4:14 PM, Jeff wrote:
>> > As a followup question, what is the best way to export data from a C
>> > program on Linux (on a system which does not have MATLAB on it) to be
>> > used in MATLAB?
>> >
>> > Just to add some detail: my advisor thinks I should just printf the
>> > data. But there is a lot of data, might this be too much for MATLAB to
>> > accept in a text file? Is there a better way?
>>
>> I'd suggest stream unformatted as much better since it will be full
>> precision and assuming the data is double quite a lot smaller of a file.
>>
>> Matlab has great flexibility in fread combined w/ fopen to handle any
>> common format currently in use.
>>
>> --
>
> Hi dpb. Thanks. Could you clarify "stream unformatted" to a C and MATLAB
> newbie (that's me)? A line or two of code which shows what you mean is
> best, because then I can just read about the commands you show. Do you
> mean "fwrite" in C or in MATLAB?

Yes. (I had added a note to that effect earlier I guess you hadn't seen).

Matlab's fopen/fread/fwrite/and friends mimic their C counterparts other
than in being vectorized to handle matrix data the syntax is the same.
So, you'll fopen() and fwrite() in C and fopen() and fread() in Matlab.

--

Tags for this Thread

No tags are associated with this thread.

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.

Contact us