Path: news.mathworks.com!not-for-mail
From: "Walter Roberson" <roberson@ibd.nrc-cnrc.gc.ca>
Newsgroups: comp.soft-sys.matlab
Subject: reading binary file from mexFunction
Date: Sun, 9 Sep 2007 22:14:43 +0000 (UTC)
Organization: National Research Council of Canada
Lines: 18
Message-ID: <fc1r8j$iql$1@fred.mathworks.com>
References: <fc1fri$au3$1@fred.mathworks.com>
Reply-To: "Walter Roberson" <roberson@ibd.nrc-cnrc.gc.ca>
NNTP-Posting-Host: webapp-06-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1189376083 19285 172.30.248.36 (9 Sep 2007 22:14:43 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 9 Sep 2007 22:14:43 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 434782
Xref: news.mathworks.com comp.soft-sys.matlab:427583


"basudha pradhan" <lucky_faith_911@hotmail.com> wrote in
message <fc1fri$au3$1@fred.mathworks.com>...
> how to read binary file from mexFunction and pass entire 
> content of file to some variable buffer? is there something 
> similar to fread() in mex function?

There is something -very- much like fread() in mex functions.

Use mxCreateDoubleArray (or as appropriate for the
type of the data to read in.) Use mxGetData on the result
of that in order to get a C pointer to the actual data
block. Use C's fopen() to open the file, and use
C's fread() to read the data into the area returned by
mxGetData. When you are done with the file, use C's fclose().


(Note: This information is based upon browsing through the
online documentation, not upon experience.)