あなたがやっていることは、「並行して配列を並べ替える」または「並列配列を並べ替える」と呼ばれています。これらの用語を使用して、それを行う方法に関するガイドを検索することができます。しかし、以下はMATLABで行う方法の1つを示すコードです:
unsorted_keys = [95, 37, 56, 70, 6, 61, 58, 13, 57, 7, 68, 52, 98, 25, 12];
unsorted_strings = cell(size(unsorted_keys));
unsorted_strings = {'crumply', 'going', 'coyotes', 'aficionado', 'bob', 'timeless', 'last', 'bloke', 'brilliant', 'reptile', 'reptile', 'reptile', 'reptile', 'reptile', 'reptile'};
[sorted_keys, indicies] = sort(unsorted_keys);
% indicies = [5, 10, 15, 8, 14, 2, 12, 3, 9, 7 6, 11, 4, 1, 13]
% So, the 5th element of unsorted_keys became the 1st element of sorted_keys
% the 10th element of unsorted_keys became the 2nd element of sorted_keys
% the 15th element of unsorted_keys became the 3rd element of sorted_keys
% the 8th element of unsorted_keys became the 4th element of sorted_keys
% and so on.....
% sorted_keys == unsorted_keys(indicies)
sorted_strings = unsorted_strings(indicies);
あなたのタグはPythonとMatlabです。どの言語を使用していますか? –
変数を実際に宣言して何かを割り当てることはできないので、Pythonの辞書がここで使われるかもしれません。 – BusyAnt
Matlabを使用すると、セルのベクトルを作成し、各文字列を対応する位置に割り当てることができます。 A {103} = 'QWE'; A {13} = '13'など...位置の大部分が空の場合は非効率的ですが、 –