Prev: how to clear variables from workspace from within a function
Next: Reading in and editing an m file
From: Tom on 18 Feb 2010 17:48 I'm using fread() to read in large binary data files with fixed-size logical records. Each logical record contains ten items, nine of which are float32 data and one of which is uint32 data. For simplicity, I read in a large chunk of data in a single fread() statement, using a "precision" string to store all read data in an array of type float32. This results in that one column of my data being incorrectly typed as float32 when it should be typed as uint32. So I extract that column to a new vector, but I can't seem to change it to interpret the existing binary data content as uint32. :( I know exactly how I'd do this if I was programming in C instead of Matlab. How do I do it here in Matlab???
From: Rune Allnor on 18 Feb 2010 17:59 On 18 Feb, 23:48, "Tom " <tsch...(a)draper.com> wrote: > I'm using fread() to read in large binary data files with fixed-size logical records. > Each logical record contains ten items, nine of which are float32 data and one of which is uint32 data. > For simplicity, I read in a large chunk of data in a single fread() statement, using a "precision" string to store all read data in an array of type float32. > This results in that one column of my data being incorrectly typed as float32 when it should be typed as uint32. > So I extract that column to a new vector, but I can't seem to change it to interpret the existing binary data content as uint32. > :( > I know exactly how I'd do this if I was programming in C instead of Matlab. > How do I do it here in Matlab??? It's the 'simplicity' of the single FREAD statement that jumped up and kicked you. Forget about casting the data in memory - that a pain at the best of times and maybe not possible. Just do what I suspect you already understood you have to do - read the data on the appropriate format first time around. If the run-time penalty is unacceptable, write a C MEX function for the file access. Rune
From: Steven Lord on 18 Feb 2010 17:59 "Tom " <tschamp(a)draper.com> wrote in message news:hlkg32$s4c$1(a)fred.mathworks.com... > I'm using fread() to read in large binary data files with fixed-size > logical records. > Each logical record contains ten items, nine of which are float32 data and > one of which is uint32 data. > For simplicity, I read in a large chunk of data in a single fread() > statement, using a "precision" string to store all read data in an array > of type float32. > This results in that one column of my data being incorrectly typed as > float32 when it should be typed as uint32. > So I extract that column to a new vector, but I can't seem to change it to > interpret the existing binary data content as uint32. > :( > I know exactly how I'd do this if I was programming in C instead of > Matlab. > How do I do it here in Matlab??? HELP TYPECAST. If you're using an older version of MATLAB that doesn't have TYPECAST, I believe someone's written an implementation and put it on the MATLAB Central File Exchange, or you could build your own MEX-file using the C approach. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Tom on 18 Feb 2010 18:13 "Steven Lord" <slord(a)mathworks.com> wrote in message <hlkgpa$bs0$1(a)fred.mathworks.com>... > > "Tom " <tschamp(a)draper.com> wrote in message > news:hlkg32$s4c$1(a)fred.mathworks.com... > > I'm using fread() to read in large binary data files with fixed-size > > logical records. > > Each logical record contains ten items, nine of which are float32 data and > > one of which is uint32 data. > > For simplicity, I read in a large chunk of data in a single fread() > > statement, using a "precision" string to store all read data in an array > > of type float32. > > This results in that one column of my data being incorrectly typed as > > float32 when it should be typed as uint32. > > So I extract that column to a new vector, but I can't seem to change it to > > interpret the existing binary data content as uint32. > > :( > > I know exactly how I'd do this if I was programming in C instead of > > Matlab. > > How do I do it here in Matlab??? > > HELP TYPECAST. > > If you're using an older version of MATLAB that doesn't have TYPECAST, I > believe someone's written an implementation and put it on the MATLAB Central > File Exchange, or you could build your own MEX-file using the C approach. > > -- > Steve Lord > slord(a)mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ > TYPECAST ? Ka-CHING ! ! ! This does indeed appear to be my solution, will try it first thing in the AM. I'm using latest R2009b Matlab. Problem sometimes is finding stuff in the help browser, especially for newly added feature. I used the "See Also" recommendations in a few other topics, but TYPECAST wasn't in there... Thanks!!!
From: Steven Lord on 19 Feb 2010 17:54 "Tom " <tschamp(a)draper.com> wrote in message news:hlkhi1$ue$1(a)fred.mathworks.com... > "Steven Lord" <slord(a)mathworks.com> wrote in message > <hlkgpa$bs0$1(a)fred.mathworks.com>... >> >> "Tom " <tschamp(a)draper.com> wrote in message >> news:hlkg32$s4c$1(a)fred.mathworks.com... >> > I'm using fread() to read in large binary data files with fixed-size >> > logical records. >> > Each logical record contains ten items, nine of which are float32 data >> > and one of which is uint32 data. >> > For simplicity, I read in a large chunk of data in a single fread() >> > statement, using a "precision" string to store all read data in an >> > array of type float32. >> > This results in that one column of my data being incorrectly typed as >> > float32 when it should be typed as uint32. >> > So I extract that column to a new vector, but I can't seem to change it >> > to interpret the existing binary data content as uint32. >> > :( >> > I know exactly how I'd do this if I was programming in C instead of >> > Matlab. >> > How do I do it here in Matlab??? >> >> HELP TYPECAST. >> >> If you're using an older version of MATLAB that doesn't have TYPECAST, I >> believe someone's written an implementation and put it on the MATLAB >> Central File Exchange, or you could build your own MEX-file using the C >> approach. >> >> -- >> Steve Lord >> slord(a)mathworks.com >> comp.soft-sys.matlab (CSSM) FAQ: >> http://matlabwiki.mathworks.com/MATLAB_FAQ > > TYPECAST ? > Ka-CHING ! ! ! > This does indeed appear to be my solution, will try it first thing in the > AM. > > I'm using latest R2009b Matlab. > Problem sometimes is finding stuff in the help browser, especially for > newly added feature. > I used the "See Also" recommendations in a few other topics, but TYPECAST > wasn't in there... > Thanks!!! I'm curious (so I can pass it along to the documentation staff) -- what were the functions or topics you looked at in which you expected to see TYPECAST (or a function to provide that operation) referenced as a See Also but didn't? -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
Next
|
Last
Pages: 1 2 Prev: how to clear variables from workspace from within a function Next: Reading in and editing an m file |