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.