Searching for log entries in SQLite that involve a particular IP subnet This reads a huge database (SQLite) and extract any IP address similar to ip_base:

for num_db=1:10
 i=1;

%     connection to different db
db_name='C:\Users\galotibi\Documents\MATLAB\user';
obj_name='jdbc:SQLite:C:\Users\galotibi\Documents\MATLAB\user';

databases=strcat(db_name,num2str(num_db),'.db');
objects=strcat(obj_name,num2str(num_db),'.db');
conn=database(databases,'','','org.sqlite.JDBC',objects);
% ----------------------------------------------------------------------


num_row='select count(*)from IP_logs';
results=exec(conn,num_row);
results=fetch(results);
Fcount=results.Data;
count=cell2mat(Fcount);
start_a=0;
start_b=10000;    
% 10000 to know how many round do we need, data is huge 
row=count/start_b;
row=ceil(row);
% rounding the value
query_base='select * from IP_logs where rowid&gt;';
wiki=cell(1,7);
for ii=1:row

        % to take 10000 record every time  
        query_1=strcat(query_base, num2str(start_a+(ii-1)*start_b));
        query_2=strcat(query_1, ' and rowid&lt;=');
        query_3=strcat(query_2, num2str(start_b*ii));

        results= exec(conn,query_3);
        results=fetch(results);


        ip_base='91.198.174.';


            for n=1:10000
                if n&gt;size(results.Data,1)
                break;
                end;
  if strncmp(results.Data(n,2), ip_base,length(ip_base)) ||     strncmp(results.Data(n,4), ip_base,length(ip_base))

                    wiki(i,:)=results.Data(n,:);
                    i=i+1;

                end


            end;


        clear results;
Databases are meant for efficient searching: you formulate a query to specify exactly what data you want to retrieve.  What you are doing is retrieving the entire contents of the table, to be filtered in MATLAB.  That defeats the purpose of the database — you might as well have stored the data in a CSV file.

Just write a query that looks like

SELECT *
    FROM IP_logs
    WHERE src_addr LIKE '91.198.174.%' OR dest_addr LIKE '91.198.174.%';


Depending on what your database schema looks like, you might be able to do even better.  Indexes on the relevant columns would help.  Storing IPv4 addresses as 32-bit integers would result in even faster searches.