このコードは、あなたが欲しいものを行う必要があります。
% Your sample arrays
A=[1;2;5;9;15]
B=[2;3;5;11;15]
C=[5;7;11;20;25]
% [A,B,C] concatenates the arrays to one single array
% Unique finds unqiues values in the input array
[D, IA, ID] = unique([A,B,C]);
disp(D);
% D = array with unique values
% ID = array with unique natural number assigned to equal values for the
% original array
% IA = array that can be referenced against ID to find the value in the
% original array
% ID and IA can be used to recreate the original array
ソリューションを「ユニーク」使用せず、これはおそらくあまり効率的である:ここでは
% SOLUTION WITHOUT USING UNIQUE
% Your variables
A=[1;2;5;9;15];
B=[2;3;5;11;15];
C=[5;7;11;20;25];
% Allocate a temporary array with your arrays concatenated
temp = sort([A;B;C]);
rep_count = 0; % Count number of repeat values
% Allocate a blank array for your output
D = zeros(length(temp),1);
D(1) = temp(1); % Initialise first element (is always unique)
% Iterate through temp and output unqiue values to D
for i = 2:length(temp)
if (temp(i) == D(i-1-rep_count))
rep_count = rep_count+1;
else
D(i-rep_count) = temp(i);
end
end
% Remove zeros at the end of D
D = D(1:length(D)-rep_count);
disp(D)
'ユニーク([A; B; C])'? – GameOfThrows
考えられる1d事前ソートされたベクトルを仮定すると[matlabでunique()を達成するための[高速な方法]の可能な複製?](http://stackoverflow.com/questions/8174578/faster-way-to-achieve-unique-in-matlab- if-assum-1d-pre-sorted-vector) – GameOfThrows
ありがとうございました。 matlabに組み込まれた 'ユニーク'を使う以外の方法はありますか? – user5916581