How to reduce time of calculation? (code includes 'for' loop with cell function)

조회 수: 1 (최근 30일)
Hallo ;), Thanks in advance
I have a data table 'P' (2772774x17) and generated another table 'aT' where the length is the unique elments from column 1 of 'P' and unique values from column 2 of 'P' as width(header). My purpose is to count the occurence of column 2 values of 'P' for each column 1 unqiue values of 'P' and save the occurences in 'aT'. This takes a very long time. Is there a possiblity to do it in a different way to save the time. Code given below:
for i=1:length(uniqueP)
count_string = cellfun(@(x) sum(ismember(P.Typ(ismember(P.ProjektID,...
uniqueP(i)),:),x)), aT.Properties.VariableNames(2:end));
% Replacing rows of a table
aT(i,2:end) = num2cell(count_string);
end
  댓글 수: 2
Sergey Kasyanov
Sergey Kasyanov 2021년 5월 6일
What data types are stored in P.ProjektID and P.Typ columns?
Kazi Alam
Kazi Alam 2021년 5월 6일
편집: Kazi Alam 2021년 5월 7일
P.ProjektID >> double
P.Typ >> Cell

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

채택된 답변

Kazi Alam
Kazi Alam 2021년 5월 7일
I changed the data search order. Earlier, the code was checking the uniqueness of the duble array then the string array. Now, the process is reveresed and it saved me hours.

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by