Vectorizing a structure assignment

3 visualizaciones (últimos 30 días)
Paolo Binetti
Paolo Binetti el 16 de Feb. de 2017
Editada: Paolo Binetti el 17 de Feb. de 2017
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

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Polyspace Software Assumptions en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by