help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Efficient I/O for 24-bit integer?


From: Peter Bodin
Subject: Re: Efficient I/O for 24-bit integer?
Date: Tue, 7 Jun 2005 14:37:31 +0200 (CEST)
User-agent: SquirrelMail/1.4.4-2

> Hello,
>
> perhaps someone on the list has a good idea for this. I am in need
> for an efficient method to read and write large arrays of 24-bit
> signed integer values to and from binary files. I have come up with
> the following:
>
> read:
> [sig, cnt] = fread(fid, [3, siz], 'uchar');
> sig0 = sig(1,:) + 256*sig(2,:) +  65536*sig(3,:);
> index = find(sig0 > 8388608);
> sig0(index) = sig0(index)-16777216;
> sig = sig0/8388608;
>
>
> write:
> sig0 = sig*8388608;
> index = find(sig0 < 0);
> sig0(index) = 16777216+sig0(index);
> s3=floor(sig0./65536);
> r=rem(sig0,66536);
> s2=floor(r./256);
> s1=rem(r,256);
> sig=[s1 s2 s3];
> fwrite(fid, sig', 'uchar');
>
> Can this be done more efficiently? The files I read contain rather
> large arrays and I would like it to work faster.
>
> Thanks for any ideas you might have.
>
> Reiner Suikat
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------
>
>


Hi!

It might be faster to use logical indexing (i.e skip the find() and
use the logical array produced by the <-operator):

index = find(sig0 > 8388608)... % would become
index = sig0 > 8388608;
sig0(index) = sig0(index)-16777216 % and so on

HTH

PB



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]