From: ara.t.howard@... Date: 2006-03-30T00:40:00+09:00 Subject: Re: reading/writing binary problem On Wed, 29 Mar 2006, Wolfgang wrote: > Hi, > > I have some binary files which I need to delete some data at the beginning of > the file (to extract the raw data out of the file). I got a matlab file from > a colleque but I would prefer if I could do it with ruby. > > This matlab code does the trick: > function m=write_rad(filename) > file=fopen(filename); > f= fread(file,'uint16'); > > [r,k]=size(f); > if k==1; > t=r-1048576; > m=f(t+1:r,:); > end > end % function > > How can I do this in ruby? I'm completely lost. > > Thanks > Wolfgang this sould be easy if i understood that method and the nature of your data ;-) here's what i understand this method to do : # open the file file=fopen(filename); # read all available unit16 quantities into an [m, n] array f= fread(file,'uint16'); # check the size of this array, r is the number of elements read [r,k]=size(f); # k will be one iff data was read into r dimension if k==1; # here i assume 1048576 is the 'row_size' of 1mb. we set t to be the offset # of the last row t=r-1048576; # because matlab is evil and uses one based indexing, we inc t by one and # extract the last row/block of data. but here it seems like the ith index # should be t+1:r-1048576 no? otherwise it seems like this would be out of # bounds? m=f(t+1:r,:); in any case this looks alot like you are trying to extract the last 1mb of uint16 quantities from a data file - is that right? let me know and i'll show you how to do this. regards. -a -- share your knowledge. it's a way to achieve immortality. - h.h. the 14th dali lama