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:
save matlab data read in other language

Subject: save matlab data read in other language

From: Zeinab Al-Rekabi

Date: 9 Jul, 2008 17:28:01

Message: 1 of 5

Hello

I am wondering can we save 3d data in matlab as .mat and
read it in IDL or other programs?

Thank you

Zeinab

Subject: save matlab data read in other language

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 9 Jul, 2008 17:37:12

Message: 2 of 5

In article <g52sf1$ra3$1@fred.mathworks.com>,
Zeinab Al-Rekabi <rekabi570@yahoo.ca> wrote:

>I am wondering can we save 3d data in matlab as .mat and
>read it in IDL or other programs?

It would probably be a nuisance in IDL, unless you loaded a DLL
to do it for you.

There is a C / C++ API for loading and saving .mat files.

Note: the license terms for use of that API say that if you
write your program to be able to read .mat format, then
it must also be able to write .mat format if they are distributed
to third-parties. For the precise conditions involved, go into the
Matlab help, and at the bottom of any help page click on Terms of Use,
and scroll down about 85% of the way and check out section 6.2 of
"6. OTHER SOURCE CODE AND SHARED OBJECT CODE LIBRARIES"
--
Q: Why did the chicken cross the Mobius strip?

A: There were manifold reasons.

Subject: save matlab data read in other language

From: Zeinab Al-Rekabi

Date: 9 Jul, 2008 19:03:03

Message: 3 of 5

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <g52t08$3aq$1@canopus.cc.umanitoba.ca>...
> In article <g52sf1$ra3$1@fred.mathworks.com>,
> Zeinab Al-Rekabi <rekabi570@yahoo.ca> wrote:
>
> >I am wondering can we save 3d data in matlab as .mat and
> >read it in IDL or other programs?
>
> It would probably be a nuisance in IDL, unless you loaded
a DLL
> to do it for you.
>
> There is a C / C++ API for loading and saving .mat files.
>
> Note: the license terms for use of that API say that if you
> write your program to be able to read .mat format, then
> it must also be able to write .mat format if they are
distributed
> to third-parties. For the precise conditions involved, go
into the
> Matlab help, and at the bottom of any help page click on
Terms of Use,
> and scroll down about 85% of the way and check out section
6.2 of
> "6. OTHER SOURCE CODE AND SHARED OBJECT CODE LIBRARIES"
> --
> Q: Why did the chicken cross the Mobius strip?
>
> A: There were manifold reasons.


Hi

Ok, what if I want to create a binary file from my existing
data on matlab. Are the following commands correct?

fid=fopen('filename', 'w', 's');
fwrite(fid, filename, 'float');

I am interested in obtaining a float data?

Thanks again

Zeinab

Subject: save matlab data read in other language

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 9 Jul, 2008 21:23:48

Message: 4 of 5

In article <g53217$a5d$1@fred.mathworks.com>,
Zeinab Al-Rekabi <rekabi570@yahoo.ca> wrote:

>Ok, what if I want to create a binary file from my existing
>data on matlab. Are the following commands correct?

>fid=fopen('filename', 'w', 's');
>fwrite(fid, filename, 'float');

>I am interested in obtaining a float data?

'float' is a native floating point format of 32 or more bits,
whatever size happens to be used for variables of type float in C.
C as a langauge defines all its native data types in terms of minimum
ranges and minimum precisions and leaves it up to the implementation
to decide what works for it -- for example on the old Cray X-MP machines,
char and short and int and float and double were all 64 bits wide.
So when you use 'float' you don't know what size you are going to get,
but it will -probably- be the same size as a C or C++ float variable.

The 's' you are passing to fopen() is

'ieee-be.l64' or 's' : IEEE floating point with big-endian byte
                       ordering and 64-bit long data type

Notice that is specifically 64 bit, but float values might well be
32 bits. You have a conflict.

If you are going to use 'float' as your conversion in fwrite()
then you should use 'n' (native) as your precision in fopen().

If you specifically want IEEE big-endian 32 bit floating point
numbers as your output, you should use 'b' as your precision
in fopen() and you should use something like 'float32' as your
conversion in fwrite().

The exact conversion you should use in fwrite() would depend upon
the data type that you are writing out. If your Matlab array is of type
single, then the conversion you should use in fwrite() would be
'float=>float32'. If your Matlab array is of type double but you
want it converted to single precision on output, then the conversion
you should use in fwrite() would be 'double=>float32'.

--
   "No one has the right to destroy another person's belief by
   demanding empirical evidence." -- Ann Landers

Subject: save matlab data read in other language

From: John Paden

Date: 1 Dec, 2011 11:52:08

Message: 5 of 5

"Zeinab Al-Rekabi" <rekabi570@yahoo.ca> wrote in message <g52sf1$ra3$1@fred.mathworks.com>...
> Hello
>
> I am wondering can we save 3d data in matlab as .mat and
> read it in IDL or other programs?
>
> Thank you
>
> Zeinab

There are C and IDL readers (each in their native language) posted at

ftp://ftp.cresis.ku.edu/mat_reader/

which read 1/2-D matrices only as of Nov 2011, but could be modified for N-D matrices without too much effort (readers are for -v6 MAT files only).

Tags for 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