Как создать и получить доступ к словарю (или карте или хеш-таблице) с помощью Octave? Я пробовал несколько способов, но, возможно, есть более эффективные способы. Ниже приведен код, чтобы показать, что я пробовал. Он использует входы от .mat файла, представленных здесь: https://www.dropbox.com/s/4v1z1q04ivpgjvf/sample_input_dictionary.mat?dl=0Как создать и получить доступ к словарю (или карте или хеш-таблице) с помощью Octave
% Methods to build/use a dictionary on Octave
clear
tic
load sample_input_dictionary.mat;
pkg load general
toc
% Dict-based dictionary, using the "general" package: very slow to access
d_dict = dict(nodes, num2cell(1:numel(nodes)));
toc
% Struct-based dictionary: slower to build, much faster to access
temp = [nodes', num2cell([1:numel(nodes)]')] .';
d_struct = struct(temp{:}); clear temp;
toc
% Is there an equivalent and more efficient cell-based dictionary?
% A different struct-based dictionary, which I could not build vectorially
t = struct();
for m=1:numel(nodes)
t.(nodes{m}) = edges{m};
end
toc
% Example of accessing the above dictionaries
d_dict('1234') % this takes forever
d_struct.('1234')
t.('1234')
Пожалуйста, покажите код, и то, что вы пробовали до сих пор, создать MCVE https://stackoverflow.com/ help/mcve – Andy
Благодарим за указание. Я добавил код. – highalpha