Filter löschen
Filter löschen

How to Speed up code

1 Ansicht (letzte 30 Tage)
elisa ewin
elisa ewin am 16 Mai 2016
Bearbeitet: Jan am 16 Mai 2016
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?

Akzeptierte Antwort

Jan
Jan am 16 Mai 2016
Bearbeitet: Jan am 16 Mai 2016
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.

Weitere Antworten (0)

Kategorien

Mehr zu Text Analytics Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by