For Programmers: Free Programming Magazines  


Home > Archive > Matlab > August 2005 > removal of loop









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author removal of loop
Phil

2005-08-31, 7:01 pm

Does anyone know how to import data, without using a loop, with the
file structure shown below. ~Phil

for i=1:n

Line_of_Data = fread(fid, 1, 'uint32');

Time = bitand(Line_of_Data,65535);
Chan = bitand(bitshift(Line_of_Data,-16),4095);
R = bitand(bitshift(Line_of_Data,-28),3);
Bin = bitand(bitshift(Line_of_Data,-30),1);

fprintf(fpout,'%7u %5u %2u', Time, Chan, R);

end;
Brett Shoelson

2005-08-31, 7:01 pm



"Phil" <not@valid.com> wrote in message news:ef129a1.-1@webx.raydaftYaTP...
> Does anyone know how to import data, without using a loop, with the
> file structure shown below. ~Phil
>
> for i=1:n
>
> Line_of_Data = fread(fid, 1, 'uint32');
>
> Time = bitand(Line_of_Data,65535);
> Chan = bitand(bitshift(Line_of_Data,-16),4095);
> R = bitand(bitshift(Line_of_Data,-28),3);
> Bin = bitand(bitshift(Line_of_Data,-30),1);
>
> fprintf(fpout,'%7u %5u %2u', Time, Chan, R);
>
> end;


Should we assume that the "1" in the fread statement should be an "i"? As
written, you are doing the exact same thing n times--never using your
iterator.
Brett
--
char(cumsum(...
[32 83 -11 7 -10 7 7 -4 -1 -46 40 -3 7 -3 15 -74 64 -5 -1 -58 57 8 7]))


Peter Boettcher

2005-08-31, 7:01 pm

Phil <not@valid.com> writes:

> Does anyone know how to import data, without using a loop, with the
> file structure shown below. ~Phil
>
> for i=1:n
>
> Line_of_Data = fread(fid, 1, 'uint32');
>
> Time = bitand(Line_of_Data,65535);
> Chan = bitand(bitshift(Line_of_Data,-16),4095);
> R = bitand(bitshift(Line_of_Data,-28),3);
> Bin = bitand(bitshift(Line_of_Data,-30),1);
>
> fprintf(fpout,'%7u %5u %2u', Time, Chan, R);


Those functions are all vectorized. It should just work if you feed
in a vector for Line_of_Data.


--
Peter Boettcher <boettcher@ll.mit.edu>
MIT Lincoln Laboratory
MATLAB FAQ: http://www.mit.edu/~pwb/cssm/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com