MATLAB Answers

0

Vectorizing a structure assignment

Asked by Paolo Binetti on 16 Feb 2017
Latest activity Edited by Paolo Binetti on 17 Feb 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

  0 Comments

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 17 Feb 2017
 Accepted Answer

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

  1 Comment

outstanding!

Sign in to comment.