From: Dave on
> >> mex mexfopen.c
> >> a = uint32(1:10);
> >> fid = fopen('uint32data','w');
> >> fwrite(fid,a,'uint32');
> >> fclose(fid);
> >> b = mexfopen('uint32data')
>
> b =
>
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
>

This example is a interesting one. However, what should I do if I want to pass the "fid" itself (not the "uint32data"-file) to the mexfopen function?
From: Rune Allnor on
On 23 Feb, 10:24, "Dave " <beha.onl...(a)gmail.com> wrote:
> > >> mex mexfopen.c
> > >> a = uint32(1:10);
> > >> fid = fopen('uint32data','w');
> > >> fwrite(fid,a,'uint32');
> > >> fclose(fid);
> > >> b = mexfopen('uint32data')
>
> > b =
>
> >      1
> >      2
> >      3
> >      4
> >      5
> >      6
> >      7
> >      8
> >      9
> >     10
>
> This example is a interesting one. However, what should I do if I want to pass the "fid" itself (not the "uint32data"-file) to the mexfopen function?

Don't.

The FID is an internal matlab variable that points to
a list of open files or streams. To pass the FID to the
MEX function you would need to

1) Know the internal workings of the matlab IO system
2) Know the internal workings of the C(++)/Fortran
IO system
3) Know how to match the two.

Not at all trivial.

If you want to access files from inside a MEX function,
pass the file name to the function and do *everything*,
from opening to closing the files, inside the MEX function.

Rune
From: James Tursa on
"Dave " <beha.online(a)gmail.com> wrote in message <hm06rm$om8$1(a)fred.mathworks.com>...
> > >> mex mexfopen.c
> > >> a = uint32(1:10);
> > >> fid = fopen('uint32data','w');
> > >> fwrite(fid,a,'uint32');
> > >> fclose(fid);
> > >> b = mexfopen('uint32data')
> >
> > b =
> >
> > 1
> > 2
> > 3
> > 4
> > 5
> > 6
> > 7
> > 8
> > 9
> > 10
> >
>
> This example is a interesting one. However, what should I do if I want to pass the "fid" itself (not the "uint32data"-file) to the mexfopen function?

If you pass the fid itself then you must call back into MATLAB to use the MATLAB fread function.

James Tursa