Performance 改善for循环性能(转换为阵列操作?)

Performance 改善for循环性能(转换为阵列操作?),performance,matlab,Performance,Matlab,我遇到了一个相当复杂的for循环操作的问题 我有一个庞大的条目列表,其中一辆车有多个条目,需要构建一个地图,告诉我哪个条目对应哪辆车 因此,我构建了一个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_li

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

我有一个庞大的条目列表,其中一辆车有多个条目,需要构建一个地图,告诉我哪个条目对应哪辆车

因此,我构建了一个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循环快得多,但我很难找到将这些函数转换为数组操作的方法

有人有改进性能的想法吗


谢谢

你没有告诉我们max是什么,实际的车是什么。我的错误是,我相应地编辑了它,max只是矩阵的末尾。