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:
Writing a .mat file without matlab

Subject: Writing a .mat file without matlab

From: Allyson Gwin

Date: 25 Oct, 2007 15:18:32

Message: 1 of 4

I am now trying to write a .mat file without matlab. I
have this web site that I think tells how to do it, but I
really don't understand it. Can someone help me out? Has
anyone done this before? We need to be able to create
the .mat file on any computer whether or not they have
matlab. This is the site:

http://www.mathworks.com/access/helpdesk/help/pdf_doc/matla
b/matfile_format.pdf#search=%22.mat%20format%22

Thanks.

Allyson

Subject: Writing a .mat file without matlab

From: Allyson Gwin

Date: 25 Oct, 2007 17:30:13

Message: 2 of 4

"Allyson Gwin" <allyson.j.gwin@lmco.com> wrote in message
<ffqc47$38a$1@fred.mathworks.com>...
> I am now trying to write a .mat file without matlab. I
> have this web site that I think tells how to do it, but
I
> really don't understand it. Can someone help me out? Has
> anyone done this before? We need to be able to create
> the .mat file on any computer whether or not they have
> matlab. This is the site:
>
>
http://www.mathworks.com/access/helpdesk/help/pdf_doc/matla
> b/matfile_format.pdf#search=%22.mat%20format%22
>
> Thanks.
>
> Allyson

Sorry, this link does not work. Here is the correct one. I
really need to write c/c++ code without using matlab at
all to get the .mat file into a binary format that matlab
can read. Some users of the c/c++ code may not have matlab
on their unix machines, but on a pc and would like to be
able to move the .mat files that are created on the unix
machine onto the pc to import into matlab. I am not sure
if this is even possible.


http://www.mathworks.com/access/helpdesk/help/pdf_doc/matla
b/matfile_format.pdf

I have no idea what I am doing so if anyone has any ideas
or has any examples of how to write out a small binary
file using c/c++, but getting it into this format, I would
really appreciate it. I know this is asking a lot. I am
really trying to figure it out for myself also. I have
matlab and have some code that writes binary files, but I
just don't exactly know how to get it to write the way
matlab writes it. Bits and bytes are a very hard concept
for me to understand. I guess I learn visually and since
you can't reall see binary code (well, you can see it, but
just not understand it), it is confusing.

Thanks for any help.

Allyson

Subject: Writing a .mat file without matlab

From: Steven Lord

Date: 25 Oct, 2007 18:39:15

Message: 3 of 4


"Allyson Gwin" <allyson.j.gwin@lmco.com> wrote in message
news:ffqc47$38a$1@fred.mathworks.com...
>I am now trying to write a .mat file without matlab. I
> have this web site that I think tells how to do it, but I
> really don't understand it. Can someone help me out? Has
> anyone done this before? We need to be able to create
> the .mat file on any computer whether or not they have
> matlab. This is the site:

I suggest you read the "Importing and Exporting Data" chapter in the
External Interfaces manual. This chapter describes the C and Fortran
MAT-file functions that you can use to create a C or Fortran program that
can read from and write to MAT-files. I recommend you use this API to write
your MAT-file instead of trying to build such an API on your own.

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/bp_kqh7.html

There are example programs for creating and reading MAT-files in both C and
Fortran in the Examples chapter of this manual as well.

--
Steve Lord
slord@mathworks.com

Subject: Writing a .mat file without matlab

From: Peter Boettcher

Date: 25 Oct, 2007 18:55:01

Message: 4 of 4

"Allyson Gwin" <allyson.j.gwin@lmco.com> writes:

> "Allyson Gwin" <allyson.j.gwin@lmco.com> wrote in message
> <ffqc47$38a$1@fred.mathworks.com>...
>> I am now trying to write a .mat file without matlab. I
>> have this web site that I think tells how to do it, but
> I
>> really don't understand it. Can someone help me out? Has
>> anyone done this before? We need to be able to create
>> the .mat file on any computer whether or not they have
>> matlab. This is the site:
>>
>>
> http://www.mathworks.com/access/helpdesk/help/pdf_doc/matla
>> b/matfile_format.pdf#search=%22.mat%20format%22
>>
>> Thanks.
>>
>> Allyson
>
> Sorry, this link does not work. Here is the correct one. I
> really need to write c/c++ code without using matlab at
> all to get the .mat file into a binary format that matlab
> can read. Some users of the c/c++ code may not have matlab
> on their unix machines, but on a pc and would like to be
> able to move the .mat files that are created on the unix
> machine onto the pc to import into matlab. I am not sure
> if this is even possible.

If at all possible, skip the MAT file generation and just use a simple
binary file. A MAT file is a very complex beast, since it needs to
store multidimensional arrays, structures, nested cell arrays, etc,
etc. If you are generating a simple data set, then fwrite the data to a
binary file (this will be fast), and in MATLAB, use fopen/fread to get
the data back out of the file.

The only downside is that a bare output file will be meaningless unless
you have the corresponding MATLAB script to read it in.

-Peter

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