I have a file that is around 250MB, and i am pretty sure that it is all ones, but i need to write a matlab script that will check this and is quick.
As far as I know, the file is one line as well:
sample: 11111111111111111111111111111111111.....
I tried the following:
fid=fopen(filename);
kk=0;
while ~feof(fid)
ONEs=textscan(fid,'%c',1000);
ONEs=cell2mat(ONEs);
if ~isequal(ONEs,num2str(ones(1000,1)))
ONEs
progress{2,kk}='Found it'
end kk=kk+1
progress(1,kk)=kk;
endand it works, but it will take days to find if there are any other characters than ones. If you have any ideas that would be great. Thanks!
textscan and cell2mat waste a lot of time. Better import the data in binary format directly. Here I use UINT8, but a CHAR would work sufficiently also. You can try to increase the block size to 10'000.
fid = fopen(FileName)
match = uint8(1);
found = [];
while ~feof(fid)
data = fread(fid, 1000, '*uint8');
if any(data ~= match)
disp('Non 1 found.');
found(end + 1) = ftell(fid);
end
end
0 Comments