Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Extraction of unique arrays in a cell

1 回表示 (過去 30 日間)
Amir Mahmoudi
Amir Mahmoudi 2024 年 9 月 19 日
閉鎖済み: Stephen23 2024 年 9 月 19 日
この 質問 は Voss さんによってフラグが設定されました
Assume there is a cell of the size 1 by N. Each cell contains an array. Some of the arrays (of the same length) are equal. How can I remove duplicate ones? Is there a unique function for cells?

回答 (1 件)

Taylor
Taylor 2024 年 9 月 19 日
One possible approach:
% Assume 'cellArray' is your 1xN cell array containing arrays
cellArray = {
[1, 2, 3],
[4, 5, 6],
[1, 2, 3], % Duplicate
[7, 8, 9],
[4, 5, 6] % Duplicate
};
% Convert each cell's array to a string representation
arrayStrings = cellfun(@mat2str, cellArray, 'UniformOutput', false);
% Find unique string representations and their indices
[~, uniqueIndices] = unique(arrayStrings, 'stable');
% Use the unique indices to create a cell array without duplicates
uniqueCellArray = cellArray(uniqueIndices);
% Display the result
disp('Cell array with duplicates removed:');
Cell array with duplicates removed:
disp(uniqueCellArray);
{[1 2 3]} {[4 5 6]} {[7 8 9]}

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by