改善环路性能(转换为阵列操作?)

时间:2015-03-30 11:26:28

标签: performance matlab

我遇到了一个相当复杂的循环操作问题。

我有一个巨大的条目列表,其中包含一个车辆的多个条目,需要建立一个“地图”,告诉我哪个条目适用于哪个车辆。

所以我建立了一个for循环:

vehicle_list = unique(Data(1:max,vehicle_column));

for i_vehicle = 1:length(vehicle_list)
  % Retrieve the actual vehicle from the list    
  vehicle = vehicle_list{i_vehicle};
  % Find all elements with the actual vehicle
  flag_vehicle = strncmp( vehicle, ...
   Data(1:end,vehicle_column), length(vehicle));

   % Set all elements with the current index (corresponding to the current
   % vehicle in the list)
   vehicle.map(flag_vehicle) = i_vehicle;
end;  

你可以想象,这需要很长时间。我尝试了使用ismember和cellfun的解决方案,但这只会让它变得更糟。

我知道数组函数比for循环要快很多但是我很难找到将这个函数转换为数组操作的方法。

有人提出改善表现的想法吗?

谢谢!

0 个答案:

没有答案
相关问题