Vectorizing a structure assignment

2 Ansichten (letzte 30 Tage)
Paolo Binetti
Paolo Binetti am 16 Feb. 2017
Bearbeitet: Paolo Binetti am 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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 17 Feb. 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{:});

Weitere Antworten (0)

Kategorien

Mehr zu Polyspace Software Assumptions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by