필터 지우기
필터 지우기

how I can minimize time of running of a code

조회 수: 1 (최근 30일)
Amr Hashem
Amr Hashem 2015년 5월 21일
댓글: Adam 2015년 5월 21일
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
Adam
Adam 2015년 5월 21일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by