Vectorizing a structure assignment

3 次查看(过去 30 天)
Is vectorizing this for-loop possible and faster?
nodes = cellstr(['GAA'; 'AACAG'; 'AAG'; 'AT'; 'ACA'; 'ACCGTTA';]); % sample input
edges = cellstr(['GAAC'; 'AACG'; 'AG'; 'ATG'; 'AC'; 'ACCG';]); % sample input
s = struct();
for m=1:numel(nodes)
s.(nodes{m}) = edges{m};
end

采纳的回答

Walter Roberson
Walter Roberson 2017-2-17
nodes = {'GAA'; 'AACAG'; 'AAG'; 'AT'; 'ACA'; 'ACCGTTA'}; % sample input
edges = {'GAAC'; 'AACG'; 'AG'; 'ATG'; 'AC'; 'ACCG'}; % sample input
temp = [nodes, edges] .';
s = struct(temp{:});

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polyspace Software Assumptions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by