how I can minimize time of running of a code

2 views (last 30 days)
Amr Hashem
Amr Hashem on 21 May 2015
Commented: Adam on 21 May 2015
I use a code to categorize data (by searching in text for words) this is the data(it consists of 40000 row):
i use this code:
tic
j=1;
k=1;
D=alldata(:,54);
E=class(D{5});
for H = 1:R % for loop to remove NaN
if isnan(D{H})
D{H} = '';
end
end
%
for E=1:2 % from 1 : length of columns
B=~cellfun('isempty',regexp(D,'deliver')) ; % search for battrey and return 1 or 0
if (B(E) == 1) % if value of array greater than or equal 1
Defs(j)=E; % save its postion (E,1)
j=j+1;
else % save all arrays didn't have 'check' separately
not(k)=E;
k=k+1;
end
end
data=alldata(Defs,:); % show data contains 'battery'
notdata=alldata(not,:); % show data didn't contain
toc
xlswrite('result2000.xlsx',data,10); % save result in sheet 4
xlswrite('result2000.xlsx',notdata,11);
but it takes very big time
2911 sec about 48 minute
and I need to run the code many times (searching for several words in 5 different columns)
how i could modify the code to run in less time ?
  1 Comment
Adam
Adam on 21 May 2015
profile on
...your code...
profile off
profile viewer
is the best way to find the slow parts of your code to focus on for speeding up. tic toc is only really useful for getting an overview of a given section of code.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!