Vectorizing a structure assignment

2 ビュー (過去 30 日間)
Paolo Binetti
Paolo Binetti 2017 年 2 月 16 日
編集済み: Paolo Binetti 2017 年 2 月 17 日
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{:});
  1 件のコメント
Paolo Binetti
Paolo Binetti 2017 年 2 月 17 日
編集済み: Paolo Binetti 2017 年 2 月 17 日
outstanding!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePolyspace Software Assumptions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by