是否可以对下面的循环进行矢量化?
% String to parse (we want to create variables that are defined implicitly in the string):
parseStr = 'cubeId=001000_X=10_Y=10_Z=10_minX=8590_maxX=9200_minY=8590_maxY=9200_minZ=87_maxZ=95';
% Splitting string for regexp
matchStr = '=|_';
[start_idx, end_idx, extents, matches, tokens, names, splits] = ...
regexp(parseStr, matchStr);
% Inspecting the splits
>> splits
splits =
Columns 1 through 8
'cubeId' '001000' 'X' '10' 'Y' '10' 'Z' '10'
Columns 9 through 15
'minX' '8590' 'maxX' '9200' 'minY' '8590' 'maxY'
Columns 16 through 20
'9200' 'minZ' '87' 'maxZ' '95'
% Loop that we are interested in vectorizing:
for ix = 1:2:numel(splits)
fields.(splits{ix}) = splits{ix+1};
end
% Result:
>>fields
fields =
cubeId: '000900'
X: '10'
Y: '9'
Z: '10'
minX: '8590'
maxX: '9200'
minY: '7590'
maxY: '8610'
minZ: '87'
maxZ: '95'