フィルターのクリア

How to Speed up code

1 回表示 (過去 30 日間)
elisa ewin
elisa ewin 2016 年 5 月 16 日
編集済み: Jan 2016 年 5 月 16 日
Hi, I have this code: I have a number of user and for all of them I want to find the id of locations that they have visited, the stay time and, combining this elements,the semantic trajectories associated to them
for userid=1:usercount
% identification locationId: the location id are in a struct s.loc_ids
for i=1:size(Trajectories(1,userid).label,1)
Trajectories(1,userid).locationId(i,1)=s(1,k).loc_ids(i,1);
end
for i=1:size(Trajectories(1,userid).label,1)-1
% stayTime (difference between time of arrival and time of exit from a cell) for every user
Trajectories(1,userid).stayTime(i,:)=abs((Trajectories(1,userid).dateAll(i+1,:)-Trajectories(1,userid).dateAll(i,:)));
% stayLocation for every user
Trajectories(1,userid).stayLocation(i,:)=[Trajectories(1,userid).locationId(i,1) Trajectories(1,userid).dateAll(i+1,:) Trajectories(1,userid).stayTime(i,:)];
% semantic trajectories for every user
Trajectories(1,userid).semanticTraj(i,:)=[Trajectories(1,userid).stayLocation(i,:) Trajectories(1,userid).label(i,:)];
end
end
It run and do what I want but It's slow: can you help me to obtain better performance?

採用された回答

Jan
Jan 2016 年 5 月 16 日
編集済み: Jan 2016 年 5 月 16 日
for userid = 1:usercount
T = Trajectories(1, userid); % Nicer code...
n = size(T.label,1);
T.locationId(1:n) = s(1,k).loc_ids(1:n);
% Or perhaps:
% T.locationId = s(1,k).loc_ids;
T.stayTime = abs(diff(T.dateAll - T.dateAll, 1, 1));
T.stayLocation = [T.locationId(1:n-1), T.dateAll(2:n, :), T.stayTime(1:n-1, :)];
T.semanticTraj = [T.stayLocation(1:n-1,:), T.label(1:n-1, :)];
Trajectories(1, userid) = T;
end
Without your data, I cannot debug this. Perhaps you need some .' operators for transposing.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Analytics Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by